S
Sérgio Pinheiro
Hi Folks,
I'm populating a combobox, with my own objects using the code bellow...
The id and descriptions are retrieved from a datareader.
Everything works fine, the items population, retrieveing of the current
selected item properties, but.... there is a problem.
How can I set the selecteditem... using this approach.
The form represents a record from one main table; on this table I'm able to
retrieve only the id's used in the comboboxes.
I've tried:
mycombobox.SelectedItem = (New ComboItem(Id, Description))
nothing happens....
mycombobox.Items.IndexOf (New ComboItem(Id, Description))
returns -1
I don't have the Index... without looping thru the items collection (this
kills the performance... because there are too many items).
The other problem is that in real scenario, at the moment I need to set the
selecteditem... I will have only the id (valuemember).
So how can I find the index of the current id or make the right item
selected?
Any suggestions are very wellcome.
thanks in advance...
-------
Id = "10023"
Description = "This is the description"
mycombo.Items.Add(new ComboItem(Id, Description)
Public Class ComboItem
Private _DisplayMember As String
Private _ValueMember As String
Public Sub New(ByVal valorIni As String, ByVal descricaoIni As String)
_ValueMember = valorIni
_DisplayMember = descricaoIni
End Sub
Public Property DisplayMember() As String
Get
Return _DisplayMember
End Get
Set(ByVal Value As String)
_DisplayMember = Value
End Set
End Property
Public Property ValueMember() As String
Get
Return _ValueMember
End Get
Set(ByVal Value As String)
_ValueMember = Value
End Set
End Property
Public Overrides Function ToString() As String
Return _DisplayMember
End Function
End Class
I'm populating a combobox, with my own objects using the code bellow...
The id and descriptions are retrieved from a datareader.
Everything works fine, the items population, retrieveing of the current
selected item properties, but.... there is a problem.
How can I set the selecteditem... using this approach.
The form represents a record from one main table; on this table I'm able to
retrieve only the id's used in the comboboxes.
I've tried:
mycombobox.SelectedItem = (New ComboItem(Id, Description))
nothing happens....
mycombobox.Items.IndexOf (New ComboItem(Id, Description))
returns -1
I don't have the Index... without looping thru the items collection (this
kills the performance... because there are too many items).
The other problem is that in real scenario, at the moment I need to set the
selecteditem... I will have only the id (valuemember).
So how can I find the index of the current id or make the right item
selected?
Any suggestions are very wellcome.
thanks in advance...
-------
Id = "10023"
Description = "This is the description"
mycombo.Items.Add(new ComboItem(Id, Description)
Public Class ComboItem
Private _DisplayMember As String
Private _ValueMember As String
Public Sub New(ByVal valorIni As String, ByVal descricaoIni As String)
_ValueMember = valorIni
_DisplayMember = descricaoIni
End Sub
Public Property DisplayMember() As String
Get
Return _DisplayMember
End Get
Set(ByVal Value As String)
_DisplayMember = Value
End Set
End Property
Public Property ValueMember() As String
Get
Return _ValueMember
End Get
Set(ByVal Value As String)
_ValueMember = Value
End Set
End Property
Public Overrides Function ToString() As String
Return _DisplayMember
End Function
End Class