combobox on form load

G

Guest

Hi,
I have a combo box that I want to populate, based on the selection of
another combo box.

So when combo box A is selected, combo box B is populated with related values.

I have this all working fine, except for on the forms loading. I have
combobox B being populated after combobox A_SelectedIndexChanged event fires.

However, on the form load, when I try to retrieve the value from
"selectedvalue" , field, it is giving me "System.Data.DataRowView". that is
the field isnt populated.

I dont understand why there is no value if the selectedindex changed event
is firing?

Can someone advise how I should be handling this. Even when the combo box
isnt yet populated, the selected index is showing as zero?.

thanks
 
V

varun kanwar

Try the following code. take two comboboxes and use the following code.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
ComboBox1.Items.Add("First")
ComboBox1.Items.Add("Second")
ComboBox1.Items.Add("Third")
ComboBox1.SelectedIndex = 0
End Sub

Private Sub ComboBox1_TextChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles ComboBox1.TextChanged
If ComboBox1.Text = "First" Then
ComboBox2.Items.Clear()
ComboBox2.Items.Add("a")
ComboBox2.Items.Add("b")
ComboBox2.Items.Add("c")
ComboBox2.SelectedIndex = 0
ElseIf ComboBox1.Text = "Second" Then
ComboBox2.Items.Clear()
ComboBox2.Items.Add("d")
ComboBox2.Items.Add("e")
ComboBox2.Items.Add("f")
ComboBox2.SelectedIndex = 0
ElseIf ComboBox1.Text = "Third" Then
ComboBox2.Items.Clear()
ComboBox2.Items.Add("g")
ComboBox2.Items.Add("h")
ComboBox2.Items.Add("i")
ComboBox2.SelectedIndex = 0
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top