Hi this bit of code shows you how to fill a combo with a sqldatareader (to
do it with a dataset is almost the same)and if you want you can also set it
to resize the dropdown part so that everything is fully displayed.
'Vul Combobox
Dim cmdReader As SqlCommand
Dim rdrReader As SqlDataReader
Dim cnComboBox As New SqlConnection("Connectionstring")
Dim blnDropDownMax As Boolean
cboCombo.Items.Clear()
cnComboBox.Open()
cmdReader = New SqlCommand("Your select statemen", cnComboBox)
rdrReader = cmdReader.ExecuteReader
Do While rdrReader.Read
If rdrReader("field") Is DBNull.Value Then
cboCombo.Items.Add("")
Else
cboCombo.Items.Add(directcast(rdrReader("field"),
String))
End If
Loop
cnComboBox.Close()
'toevoeging door Peter 16/12/2004 voor het automatisch
groter maken van de
'dropdown zodat deze even groot is als het grootste item
'Resize of the dropdownpart
If blnDropDownMax = True Then
Dim ds As Graphics = cboCombo.CreateGraphics
Dim x As Single = 0
Dim str As String
For Each str In cboCombo.Items
x = Math.Max(x, ds.MeasureString(str,
cboCombo.Font).Width)
Next
cboCombo.DropDownWidth = CInt(x) + 7
ds.Dispose()
End If
End If
End Sub
Be aware there's no error handling, you have to add that yourself. It's just
an example to get you started
hth Peter