|
-
September 3rd, 2008, 07:41 PM
#1
[RESOLVED] Cannot Retreive Value Member of first Item in Combo Box
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
-
September 3rd, 2008, 11:26 PM
#2
Re: Cannot Retreive Value Member of first Item in Combo Box
The combo box index starts with 0, so you use the
Code:
From 0 to myCntrl.Count-1
-
September 4th, 2008, 01:09 PM
#3
Re: Cannot Retreive Value Member of first Item in Combo Box
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
-
September 4th, 2008, 01:13 PM
#4
Re: Cannot Retreive Value Member of first Item in Combo Box
You don't have to bind the data to the combo, if you fill it yourself.
-
September 5th, 2008, 02:27 PM
#5
Re: Cannot Retreive SelectedValue of first Item in Combo Box
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|