Search KB Filter article types
ListBox CodeSample - Populating with List of KeyValuePair objects
Categories: Selection, Built-in
Tags: Developers, Data Binding, 1. Beginner, Data Binding, Pre v6.3, v6.3, v6.4 and Later, 2. Intermediate, 3. Advanced
Revision: 1
Posted: 04/Oct/2009
Updated: 23/July/2010
Status: Publish
Types: Code

This article will have a few sections added to it soon, based on the following article type skeleton: CodeSample
Overview

This codesample demonstrates how you can populate ListBox by creating a List of KeyValuePair objects and assigning to the DataSource.

VB.NET Code
Imports Gizmox.WebGui.Forms
Public Class KVPListBox
    Inherits ListBox
    Private uList As List(Of KeyValuePair(Of String, String)) = New List(Of KeyValuePair(Of String, String))
    Sub New()
        MyBase.New()
    End Sub
 
    Friend Sub ReloadData()
 
        uList.Add(New KeyValuePair(Of String, String)("001", "Tommy twodime"))
        uList.Add(New KeyValuePair(Of String, String)("002", "Jhonny boy"))
        uList.Add(New KeyValuePair(Of String, String)("003", "John Doe"))
        uList.Add(New KeyValuePair(Of String, String)("004", "Homer Simpson"))
        uList.Add(New KeyValuePair(Of String, String)("005", "Superman"))
 
        uList.Sort(AddressOf CompareKVP)
        Me.DataSource = uList
        Me.ValueMember = "Key"
        Me.DisplayMember = "Value"
    End Sub
 
    Private Shared Function CompareKVP( _
       ByVal x As KeyValuePair(Of String, String), ByVal y As KeyValuePair(Of String, String)) As Integer
 
        Return x.Value.CompareTo(y.Value)
 
    End Function
 
End Class
 
' In your form, after instanciating an object of type KVPListBox, in this example you will have to call:
KvpListBox1.ReloadData()

C# Code
The conversion of this code to C# has not been completed yet.

About the author

Related Articles

Selection  
Title Update Author
Tags: Developers, Data Binding, Navigation, 1. Beginner, 2. Intermediate, Data Binding, Navigation, ASP.NET, Pre v6.3, v6.3, v6.4 and Later, 3. Advanced
11/Jan/2009    2009/01/11
Control of a combobox with a checked list and a tree.
Tags: Developers, Navigation, 2. Intermediate, 3. Advanced, Customization, Layouting, Navigation, Pre v6.3, v6.3, v6.4 and Later
06/Jan/2008    2008/01/06
This code demonstrates the usage of the different AutoCompleteMode values property of ComboBox control
Tags: Developers, Data Binding, Navigation, 1. Beginner, 2. Intermediate, 3. Advanced, Navigation, Pre v6.3, v6.3, v6.4 and Later
12/Jan/2007    2007/01/12
Tags: Developers, Data Binding, Windows & Dialogs, 1. Beginner, 2. Intermediate, Customization, Data Binding, Pre v6.3, v6.3, v6.4 and Later, 3. Advanced
03/Jan/2009    2009/01/03
Tags: Architects, Developers, 1. Beginner, 2. Intermediate, 3. Advanced, Pre v6.3, v6.3, v6.4 and Later
04/Dec/2010    2010/12/04
Tags: Developers, 1. Beginner, 2. Intermediate, Pre v6.3, v6.3, v6.4 and Later, 3. Advanced
21/July/2010    2010/07/21
.NET HTML5 Web, Cloud and Mobile application delivery | Sitemap | Terms of Use | Privacy Statement | Copyright © 2005-2012 Visual WebGui®       Visual WebGui weblog on ASP.NET Gizmox Blog Visual WebGui Group on LinkedIn Visual WebGui updates on Twitter Visual WebGui Page on Facebook Visual WebGui YouTube Channel Visual WebGui Platform News RSS