|
-
Feb 26th, 2009, 03:23 AM
#1
Thread Starter
Lively Member
Combo Box refresh
Hi, I have a tabcontrol with two pages. In the first page there is a form where the user fills it and clicks on a button in order to store (in a sql database) the values. On the second tabpage there is a combobox where when I open it I want to display the values of a specific field of a database table. I did this but I am having the above problem. I am retriving the values for the combobox on combobox's mousedown event. So, when I click again it doubles the displayed values, triples on the third click etc. How can I make it display the values only one time? The code I am using for the populating of the combobox is the following:
Private Sub CmbUsername_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles CmbUsername.MouseDown
objConnection.Open()
objDataAdapter.SelectCommand = New SqlCommand()
objDataAdapter.SelectCommand.Connection = objConnection
objDataAdapter.SelectCommand.CommandText = _
"SELECT UserName FROM Users "
objDataAdapter.SelectCommand.CommandType = CommandType.Text
objDataAdapter.Fill(objDataSet, "UserName")
'Εμφάνιση των τιμών του datatable στο Combobox
CmbUsername.DataSource = objDataSet.Tables("UserName")
CmbUsername.DisplayMember = "UserName"
objConnection.Close()
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|