I am populating a combobox by connecting a datasource from an sql statement.
dt = select Name as [Name], Code as [Id] from Table
Then I want to se the default value of the combobox to "Nick" which I am locating with the following code
For Each i as DataRowView in comboBox.Items
If i("Name").ToString="Nick" Then
comboBox.SelectedIndex=selectedCount
Exit For
End If
selectedCount=selectedCount +1
Next
This will correctly display "Nick" as the default in the comboBox, but when I go and get the selectedValue with the following code it is getting the selected index of the first item in the list not the delfault item "Nick".
When I click a button and look at the SelectedIndex of the combobox it is set back to 0 eventhough it displays the correct selectedValue in the comboxbox.
item=comboBox.SelectedValue.ToString
How do I get the selected Value I defaulted the combobox to?