Click to See Complete Forum and Search --> : [RESOLVED] Cannot Retreive Value Member of first Item in Combo Box


Pullayniece
September 3rd, 2008, 07:41 PM
Hi,

I am trying to program a combo box with the data source properties set via the visual settings option instead of programatically. I have connected the Display Member of the combo box to the Name field of the Table, and the value member to the ID field.

I have written a routine to call the selected value of the combo box by button in a message box to test to see which ID is currently selected. Everything seems to pulling ok, however the first listed item in the combo box is retrieving the second item's ID. And if I choose another item in the list and then choose the first item again, the previous item's ID value is still diaplayed when I test the selectedvalue settings.

I was wondering what I need to in order to retrieve the first item's ID when selected, I have tried adding an empty item, however VB.NET 2005 will not let you do this when the data source properties are set. Thank you for your time. Below is the code created by the visual aid data source properties.

Try

Me.ChurchTableAdapter.Fill(Me.DsNewFamily1.Church)

Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try

dglienna
September 3rd, 2008, 11:26 PM
The combo box index starts with 0, so you use the

From 0 to myCntrl.Count-1

Pullayniece
September 4th, 2008, 01:09 PM
thanks for the tip, I figured it probably had to do with combo boxes being 0 base. I used your advice with the code below, and it works if the first item is not changed to another from the combo box, however once another item from the list is selected and then the user re-selects the first item it still grabs the value member from the previous item selected.

For i As Integer = 0 To cbChurchList.Items.Count - 1

MessageBox.Show("This is the GUID of the Selected Church : " & " " & cbChurchList.SelectedValue.ToString(), "GUID Information")

' Exit Sub
Next

dglienna
September 4th, 2008, 01:13 PM
You don't have to bind the data to the combo, if you fill it yourself.

Pullayniece
September 5th, 2008, 02:27 PM
yes I know I can just code the connection, however the examples I have seen have with the 1.1 Framework not 2.0, also I would to eventually pull the SQL commands from database itself rather than in the application pillar.