By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,993 Members | 1,883 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,993 IT Pros & Developers. It's quick & easy.

Combo Box Is showing default value!!!

P: 77
Hi All,

I have problem with combo box. It is funny but I don't know what to do. When I load my form I load my combos with this Sub:
Expand|Select|Wrap|Line Numbers
  1.     Private Sub CityLoad()
  2.         Dim sql As String
  4.         Dim ds1 As New DataSet
  5.         Dim ds2 As New DataSet
  6.         Dim con As SqlConnection
  7.         Dim da As SqlDataAdapter
  8.         sql = "SELECT *  FROM tbl_city"
  9.         con = New SqlConnection(StrCon)
  10.         con.Open()
  11.         da = New SqlDataAdapter(sql, con)
  12.         '***CityIni
  13.         da.Fill(ds1)
  14.         cboCityIni.DataSource = ds1.Tables(0)
  15.         cboCityIni.ValueMember = ds1.Tables(0).Columns  (0).ColumnName.ToString
  16.         cboCityIni.DisplayMember = ds1.Tables(0).Columns(1).ColumnName.ToString
  17.         cboCityIni.Text = ""
  18.         ds1 = Nothing
  19.         '***CitySec
  20.         da.Fill(ds2)
  21.         cboCitySec.DataSource = ds2.Tables(0)
  22.         cboCitySec.ValueMember = ds2.Tables(0).Columns(0).ColumnName.ToString
  23.         cboCitySec.DisplayMember = ds2.Tables(0).Columns(1).ColumnName.ToString
  24.         cboCitySec.Text = ""
  26.     End Sub
Both of these combos are loaded with City but the problem is when I run the application I need to see empty combo(I mean it should not show any value till the user click on them.)
Surprizingly second combo is showing the first item in the combo when form is loaded.

What should I do?
Aug 6 '08 #1
Share this Question
Share on Google+
4 Replies

Expert 5K+
P: 7,872
Add a blank row to the begining of your datatable? Really I am surprised that they both did not autoselect the first value
Aug 6 '08 #2

P: 77
Thanks .
Can you tell me how to do that?
Aug 6 '08 #3

P: 77
I found a easy way

Combo.SelectedValue = 0
Aug 7 '08 #4

Expert 5K+
P: 7,872
Ahh ses I assumed you already had that. you DO have a blank link at the begining, good.
Not sure why it didn't default to that position. Glad you found a fix.
Aug 7 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.