populating dropdown in windows forms
i have a form with a dropdown
i am populating dropdowmn from database but having few issues
i have a sub function fr populating the dropdown as
Dim da1 As New SqlDataAdapter(cmd1)
Dim ds1 As New DataSet()
da1.Fill(ds1, "M_customer")
Me.drpcust.DataSource = ds1
Me.drpcust.DisplayMember = "Cname"
Me.drpcust.ValueMember = "CID"
but after this line Me.drpcust.DataSource = ds1 the prg flow jumps to another sub function
having If drpcust.SelectedIndex = -1 Then
cmdsave.Enabled = False
Button1.Enabled = False
which shld not happen
and even he dropdown is not getting populated
Re: populating dropdown in windows forms
You message is not very clear, If what you are saying is that you are calling another sub routine which checks the selectedindex before you have even assigned the members of the list then it would be = -1 as nothign would be selected nor would I expect anything to be in the list.
Show the code including the sub routine call and the code of the sub routine and use code tags with proper indenting so as to make it easy to read.
Re: populating dropdown in windows forms
this code ....
Code:
Me.drpcust.DataSource = ds1
will ALWAYS trigger the drpcust.SelectedIndexChanged event, because the list is been changed, and thus the index has changed too...
If you do not want this action then you have to add a Bool to check and skip if your Binding the data source..
The reason your probably getting nothing in the DDL is there is a Problem with your Data.. check the da1.Count value for how many items are in the dataset...