Hi all,
I'm sure I'm doing something silly here, but can't see it!
I'm creating a series of combo boxes on a Windows Form in VB.NET.
The lists of all of the comboboxes are identical and are held in a
table in a dataset and the number created is based on the number of
rows in a second table in the same dataset.
Code snippets
For i = 0 To mobjDataSet.Tables(mstrDriversTableName).Rows.Coun t - 1
..
..
..
'add the start positions
objCurrentComboBox = New ComboBox()
objPointsScheme.ListControlPopulateForms( _
objCurrentComboBox, _
mobjDataSet, _
"tblPointsScheme", _
False, _
True)
With objCurrentComboBox
.Left = 103
.Name = "cboStartPosition" & i.ToString
.Top = 35 + (i * 25)
.Width = 50
End With
Me.Controls.Add(objCurrentComboBox)
..
..
..
Next
Public Sub ListControlPopulateForms( _
ByRef objControl As System.Windows.Forms.ListControl, _
ByVal objDataSet As DataSet, _
ByVal strTableName As String, _
ByVal blnNoneEntryAdd As Boolean, _
ByVal blnSelectTextAdd As Boolean)
'populates the supplied listbox control with Points Schemes from
the table
Dim aryPointsSchemeDetails As ArrayList = New ArrayList()
Dim objPointsSchemeDetail As clsPointsSchemeDetail
'create an array of points scheme details
For Each objCurrentTableRow In
objDataSet.Tables(strTableName).Rows
objPointsSchemeDetail = New clsPointsSchemeDetail()
With objPointsSchemeDetail
.Id = objCurrentTableRow.Item("Id")
.intPoints = objCurrentTableRow.Item("intPoints")
.strPosition = objCurrentTableRow.Item("strPosition")
End With
aryPointsSchemeDetails.Add(objPointsSchemeDetail)
Next
'bind the array to the combo box and select the field to show the
position
With objControl
.DataSource = aryPointsSchemeDetails
.DisplayMember = "strPosition"
.ValueMember = "Id"
End With
'change the text of the listbox if necessary
If blnSelectTextAdd Then
objControl.Text = "Select"
End If
End Sub 'ListControlPopulateForms
Everything runs without an error, each combobox has the correct number
of entries in the list, but the text of each contains
'FormulaDe.Business.clsPointsSchemeDetail' which is the namespace/name
of the class, but is definitely not the contents of the strPosition
field.
The code is essentially copied from the ListControl.Datasource
Property entry in the .Net Framework SDK Documentation.
What am I doing wrong?
Cheers,
Duncan