|
-
Jul 12th, 2004, 06:24 AM
#1
Thread Starter
Hyperactive Member
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 ??
-
Jul 12th, 2004, 06:35 AM
#2
Place your elements into an ArrayList, and then set the listbox's datasource as that arraylist.
-
Jul 12th, 2004, 06:42 AM
#3
Here's my most used example on the forums 
'First, declare a class to hold your stuff
VB Code:
Public Class ListItemNumeric
Private mstrValue As String
Private mintID As Integer
Public Sub New()
End Sub
Public Sub New(ByVal strValue As String, ByVal intID As Integer)
mstrValue = strValue
mintID = intID
End Sub
Property Value() As String
Get
Return mstrValue
End Get
Set(ByVal Value As String)
mstrValue = Value
End Set
End Property
Property ID() As Integer
Get
Return mintID
End Get
Set(ByVal Value As Integer)
mintID = Value
End Set
End Property
Public Overrides Function ToString() As String
Return mstrValue
End Function
End Class
Now, you can populate your listbox:
VB Code:
Dim lItem As ListItemNumeric
lItem.Value = "HORSE"
lItem.ID = 9
lstListBox.Items.Add(lItem)
Add them however you want.
Now, when you want to work with them, do like so:
VB Code:
varVariableName = CType(lstListBox.SelectedItem, ListItemNumeric).ID
'or Value, whatever you want
HTH!
-
Jul 12th, 2004, 06:45 AM
#4
Thread Starter
Hyperactive Member
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 ... ??
-
Jul 12th, 2004, 11:26 AM
#5
Thread Starter
Hyperactive Member
no other way
-
Jul 12th, 2004, 11:57 PM
#6
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?
-
Jul 13th, 2004, 06:17 AM
#7
Thread Starter
Hyperactive Member
That is certainly possible, but then I'd have to ask myself a question, is it worth ?
-
Jul 13th, 2004, 07:04 AM
#8
And deep inside you a small voice will say "I need a drink"
-
Jul 13th, 2004, 07:48 AM
#9
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|