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 ??
Printable View
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 ??
Place your elements into an ArrayList, and then set the listbox's datasource as that arraylist.
Here's my most used example on the forums :D
'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! :afrog:
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 ... ??
no other way :(
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?
That is certainly possible, but then I'd have to ask myself a question, is it worth ?
And deep inside you a small voice will say "I need a drink"
You got that one right :pQuote:
Originally posted by mendhak
And deep inside you a small voice will say "I need a drink"