ericamick
asked on
SelectedValue weirdness in combobox tied to Access database
Under .NET 2.0 with Visual Studio 2005, I have a combobox on a form that is getting its data from an Access database. It's set up to display one column from the table and return another column's value when an item is selected. When I look at what's in SelectedValue, it contains two copies of the value from the database row. The row is not duplicated in the table, and it appears to be selecting the correct row. Does anyone have any hints as to what might be going on? I set up the associated dataset using the wizard, in case that matters.
You should post some code in order to be helped. Like how do you set properties DisplayMember, ValueMember, DataSource, and with what parameters did you call comboBox.DataBindings.Add metod.
ASKER
I set DisplayMember, ValueMember, and DataSource through the form designer, and I don't call the DataBindings.Add method myself--I just let the designer do all that for me. My code simply stores the SelectedValue property's value in a private variable in the class during a button click event handler, and I access that value through a read-only property.
So, if you dont give any code, how do you think we will be able to help you? If you say that databinding is done correctly, and you take the SelectedItem value correctly, then I dont see the reason why it should work. :)
ASKER
Here's the code. Let me know what else you need.
Public Class CommAmdtList
Private XMLFragment As String
Private Sub CommAmdtList_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'CommDataSet.CommitteeAmdt' table. You can move, or remove it, as needed.
Me.CommitteeAmdtTableAdapter.Fill(Me.CommDataSet.CommitteeAmdt)
End Sub
Private Sub btnOK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOK.Click
XMLFragment = AmdtList.SelectedValue
End Sub
ReadOnly Property XML() As String
Get
Return XMLFragment
End Get
End Property
End Class
ASKER
Here's one additional clue: The doubling of the value occurs only when the first item in the combo box is selected, i.e., SelectedIndex = 0.
This is not the code I meant, I need, as I said in my first post, the code that you use to bind the combobox. If I understood you correctly
Private Sub btnOK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOK.Click
' this is the place where you load data from selected value
XMLFragment = AmdtList.SelectedValue
' add one messagebox just so we can see what if the incorrect value is captured
MessageBox.Show(XMLFragmen t)
End Sub
I need the code where you bind combobox. It is somewhere in the code behind the form, and never use designers, just becuase they usually cause trouble (like you are having now), so I cant tell where exactly did it put it.
Private Sub btnOK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOK.Click
' this is the place where you load data from selected value
XMLFragment = AmdtList.SelectedValue
' add one messagebox just so we can see what if the incorrect value is captured
MessageBox.Show(XMLFragmen
End Sub
I need the code where you bind combobox. It is somewhere in the code behind the form, and never use designers, just becuase they usually cause trouble (like you are having now), so I cant tell where exactly did it put it.
ASKER
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you should basically delete questions, since the post doesn't contain the actual answer, if someone else has the same problem. :)
you should basically delete question, since the post doesn't contain the actual answer, if someone else has the same problem. :)