H
HolyHarley
I have been working in VB.net and have been using the combobox to
store data I need when the user selects an item. To do this, I have
been creating a class of some data.
Private Class Relationship
Public _code As String
Public _description As String
Public _default As Boolean
Public Sub New(ByVal sCode As String, ByVal sDescription As
String, ByVal bDefault As Boolean)
Me._code = sCode.Trim & ""
Me._description = sDescription.Trim & ""
Me._default = bDefault
End Sub
Public ReadOnly Property ListEntry() As String
Get
Return Me._code & " -- " & Me._description
End Get
End Property
End Class
I then load the combobox with data.
Private Sub LoadRelationship()
Try
Dim dr As SqlDataReader = _dropDown.GetRelationship
Me.cboRelationship.DisplayMember = "ListEntry"
While dr.Read
Me.cboRelationship.Items.Add(New
Relationship(dr.Item("code"), dr.Item("description"),
dr.Item("initial")))
End While
Catch ex As Exception
MsgBox(ex.ToString, MsgBoxStyle.Information +
MsgBoxStyle.OKOnly, "frmXXClientAddEdit.LoadRelationship Error...")
End Try
End Sub
Then when the user select an item, I cam access the code, description
or initial using the following:
If Me.cboRelationship.SelectedIndex <> -1 Then
.RelationCode = DirectCast(Me.cboRelationship.Items(Me.cboRelationship.SelectedIndex),
Relationship)._code
Else
.RelationCode = ""
End If
I found this very useful, especially when you expand the data stored
in the combobox.
In C# I have been able to get to the point where the data is stored in
the combobox, but I have not been able to get the data out. I will
need to access both the ID (int) field and the Description (string)
values, so the valuemember does not appear to cut it.
Appreciate any help.
Thanks.
Jeff
store data I need when the user selects an item. To do this, I have
been creating a class of some data.
Private Class Relationship
Public _code As String
Public _description As String
Public _default As Boolean
Public Sub New(ByVal sCode As String, ByVal sDescription As
String, ByVal bDefault As Boolean)
Me._code = sCode.Trim & ""
Me._description = sDescription.Trim & ""
Me._default = bDefault
End Sub
Public ReadOnly Property ListEntry() As String
Get
Return Me._code & " -- " & Me._description
End Get
End Property
End Class
I then load the combobox with data.
Private Sub LoadRelationship()
Try
Dim dr As SqlDataReader = _dropDown.GetRelationship
Me.cboRelationship.DisplayMember = "ListEntry"
While dr.Read
Me.cboRelationship.Items.Add(New
Relationship(dr.Item("code"), dr.Item("description"),
dr.Item("initial")))
End While
Catch ex As Exception
MsgBox(ex.ToString, MsgBoxStyle.Information +
MsgBoxStyle.OKOnly, "frmXXClientAddEdit.LoadRelationship Error...")
End Try
End Sub
Then when the user select an item, I cam access the code, description
or initial using the following:
If Me.cboRelationship.SelectedIndex <> -1 Then
.RelationCode = DirectCast(Me.cboRelationship.Items(Me.cboRelationship.SelectedIndex),
Relationship)._code
Else
.RelationCode = ""
End If
I found this very useful, especially when you expand the data stored
in the combobox.
In C# I have been able to get to the point where the data is stored in
the combobox, but I have not been able to get the data out. I will
need to access both the ID (int) field and the Description (string)
values, so the valuemember does not appear to cut it.
Appreciate any help.
Thanks.
Jeff