stevecking
Active member
- Joined
- Dec 27, 2006
- Messages
- 32
- Programming Experience
- 5-10
I'm confused by what should be a relatively straight forward design. It uses an ArrayList with classes added which is the DataSource for a combobox. The DisplayMember is then "LastFirst" and the ValueMember is the ID of the name. Sometimes the dropdown on the combobox is empty, sometimes the combobox seems to display the "LastFirst" correctly but after selecting it the text disappears. I've been quite unsuccessful figuring this rather simple seeming issue out. Any help would be appreciated.
Public Class LookupName
Private _ID As Integer
Private _FirstName As String
Private _LastName As String
Public Sub New(ByVal ID As Integer, ByVal FirstName As String, ByVal LastName As String)
_ID = ID
_FirstName = FirstName
_LastName = LastName
End Sub
Public ReadOnly Property ID() As Integer
Get
ID = _ID
End Get
End Property
Public ReadOnly Property FirstName() As String
Get
FirstName = _FirstName
End Get
End Property
Public ReadOnly Property LastName() As String
Get
LastName = _LastName
End Get
End Property
Public ReadOnly Property LastFirst() As String
Get
Return _LastName & ", " & _FirstName
End Get
End Property
Public Overrides Function ToString() As String
Return _LastName & ", " & _FirstName
End Function
End Class
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.TblDataTableAdapter.Fill(Me._MyDatabase_1DataSet.tblData)
Using Cnn As New SqlServerCe.SqlCeConnection(My.Settings.dbConnectionString.ToString)
Dim cmd As New SqlServerCe.SqlCeCommand("SELECT ID, First, Last FROM Names", Cnn)
cmd.CommandType = CommandType.Text
Cnn.Open()
Dim dr As SqlServerCe.SqlCeDataReader = cmd.ExecuteReader
While dr.Read
comboArray.Add(New LookupName(dr("ID"), dr("First"), dr("Last")))
End While
Me.NameIDComboBox.DataSource = comboArray
With Me.NameIDComboBox
.DataSource = comboArray
.DisplayMember = "LastFirst"
.ValueMember = "ID"
.DataBindings.Add("SelectedValue", TblDataBindingSource, "NameID")
End With
End Using
End Sub
Public Class LookupName
Private _ID As Integer
Private _FirstName As String
Private _LastName As String
Public Sub New(ByVal ID As Integer, ByVal FirstName As String, ByVal LastName As String)
_ID = ID
_FirstName = FirstName
_LastName = LastName
End Sub
Public ReadOnly Property ID() As Integer
Get
ID = _ID
End Get
End Property
Public ReadOnly Property FirstName() As String
Get
FirstName = _FirstName
End Get
End Property
Public ReadOnly Property LastName() As String
Get
LastName = _LastName
End Get
End Property
Public ReadOnly Property LastFirst() As String
Get
Return _LastName & ", " & _FirstName
End Get
End Property
Public Overrides Function ToString() As String
Return _LastName & ", " & _FirstName
End Function
End Class
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.TblDataTableAdapter.Fill(Me._MyDatabase_1DataSet.tblData)
Using Cnn As New SqlServerCe.SqlCeConnection(My.Settings.dbConnectionString.ToString)
Dim cmd As New SqlServerCe.SqlCeCommand("SELECT ID, First, Last FROM Names", Cnn)
cmd.CommandType = CommandType.Text
Cnn.Open()
Dim dr As SqlServerCe.SqlCeDataReader = cmd.ExecuteReader
While dr.Read
comboArray.Add(New LookupName(dr("ID"), dr("First"), dr("Last")))
End While
Me.NameIDComboBox.DataSource = comboArray
With Me.NameIDComboBox
.DataSource = comboArray
.DisplayMember = "LastFirst"
.ValueMember = "ID"
.DataBindings.Add("SelectedValue", TblDataBindingSource, "NameID")
End With
End Using
End Sub