Trouble in getting combobox populated in windows form!
Hi experts,
I want to populate a combobox in windows form in vb.net, but I am having trouble to get it right, here is my code:
Private Sub cboTALXChkDt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboTALXChkDt.Click
cboTALXChkDt.Items.Clear()
Dim cmdCheckDate As New SqlCommand
Dim dtrCheckDate As SqlDataReader
Dim conGPDb As New SqlClient.SqlConnection
conGPDb.ConnectionString = "....................."
With cmdCheckDate
.Parameters.Clear()
.CommandText = "SELECT DISTINCT CHEKDATE FROM UPR30300 WHERE YEAR1 = 2006 ORDER BY CHEKDATE"
.Connection = conGPDb
End With
conGPDb.Open()
dtrCheckDate = cmdCheckDate.ExecuteReader()
While dtrCheckDate.Read()
cboTALXChkDt.Items.Add(dtrCheckDate("CHEKDATE"))
End While
cboTALXChkDt.SelectedIndex = 0
dtrCheckDate.Close()
End Sub
------------------------------------------
1. When it's populated, the name of combobox shows up in the box, followed by the items. How to prevent this name of combobox showing up in the box when it's populated? (the first item gets populated after I clicked the dropdown arrow).
2. It shows only one item for the first time I clicked the dropdown arrow of combobox, but the 2nd time I click it, it populates more items to view.....I need it to be populated 10 items a time, so Any suggestion?
Please help. Thank you.