Question : In ComboBox, Adding - Select Item on index -1


VS 2005 / Vb.Net

 cmbState.DataSource = objDs.Tables(0)
        cmbState.Items.Insert(-1, "-- Select --")
        cmbState.DisplayMember = "StateShortName"
        cmbState.ValueMember = "StateID"

Answer : In ComboBox, Adding - Select Item on index -1

First add a new row to the dataset you are binding to the combobox and set values for the row and then insert that row at first postion.

Dim dr As DataRow = objDs.Tables(0).NewRow()
' create a new row into the dataset
dr(0) = "-- Select --"
dr(1) = 1102
.
.
.
objDs.Tables(0).Rows.InsertAt(dr, 0)

and now bind your dataset to the combo box
Random Solutions  
 
programming4us programming4us