Results 1 to 9 of 9

Thread: combobox/listbox

  1. #1

    Thread Starter
    Hyperactive Member spoiledkid's Avatar
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    437

    combobox/listbox

    How do you use the DisplayMember and ValueMember properties of combobox and listbox when you are not binding it with a data source. Can't I manually Additems using Items.Add and still specify these two things ??

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Place your elements into an ArrayList, and then set the listbox's datasource as that arraylist.

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Here's my most used example on the forums


    'First, declare a class to hold your stuff

    VB Code:
    1. Public Class ListItemNumeric
    2.     Private mstrValue As String
    3.     Private mintID As Integer
    4.     Public Sub New()
    5.  
    6.     End Sub
    7.  
    8.     Public Sub New(ByVal strValue As String, ByVal intID As Integer)
    9.         mstrValue = strValue
    10.         mintID = intID
    11.  
    12.     End Sub
    13.  
    14.     Property Value() As String
    15.         Get
    16.             Return mstrValue
    17.         End Get
    18.         Set(ByVal Value As String)
    19.             mstrValue = Value
    20.  
    21.         End Set
    22.     End Property
    23.  
    24.     Property ID() As Integer
    25.         Get
    26.             Return mintID
    27.         End Get
    28.         Set(ByVal Value As Integer)
    29.             mintID = Value
    30.         End Set
    31.     End Property
    32.  
    33.     Public Overrides Function ToString() As String
    34.         Return mstrValue
    35.     End Function
    36.  
    37. End Class


    Now, you can populate your listbox:

    VB Code:
    1. Dim lItem As ListItemNumeric
    2.  
    3. lItem.Value = "HORSE"
    4. lItem.ID = 9
    5.  
    6. lstListBox.Items.Add(lItem)

    Add them however you want.

    Now, when you want to work with them, do like so:

    VB Code:
    1. varVariableName = CType(lstListBox.SelectedItem, ListItemNumeric).ID
    2. 'or Value, whatever you want

    HTH!

  4. #4

    Thread Starter
    Hyperactive Member spoiledkid's Avatar
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    437
    That is the problem, I have an XML in this format ...


    m_entityGuids = "<Entities>" & Environment.NewLine
    m_entityGuids = m_entityGuids & "<Entity Name=""a"" Guid=""b"" />" & Environment.NewLine
    m_entityGuids = m_entityGuids & "<Entity Name=""c"" Guid=""d"" />" & Environment.NewLine
    m_entityGuids = m_entityGuids & "</Entities>"


    Now, I am suppose to look through the XMLDocument and load Name as a visible thing and Guid as the value of the name. How Do I do that with datasource property ... ??

  5. #5

    Thread Starter
    Hyperactive Member spoiledkid's Avatar
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    437
    no other way

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Isn't it possible to parse through that XML file and get these values, then populate the ListItemNumeric like in the example I showed you?

  7. #7

    Thread Starter
    Hyperactive Member spoiledkid's Avatar
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    437
    That is certainly possible, but then I'd have to ask myself a question, is it worth ?

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    And deep inside you a small voice will say "I need a drink"

  9. #9

    Thread Starter
    Hyperactive Member spoiledkid's Avatar
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    437
    Originally posted by mendhak
    And deep inside you a small voice will say "I need a drink"
    You got that one right

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width