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.
LVL 1
ericamickAsked:
Who is Participating?
 
ericamickConnect With a Mentor Author Commented:
It turns out the data in the database had the value duplicated, but I didn't realize it. Chalk up another one to user error.
0
 
Priest04Commented:
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.
0
 
ericamickAuthor Commented:
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.
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
Priest04Commented:
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. :)
0
 
ericamickAuthor Commented:
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

Open in new window

0
 
ericamickAuthor Commented:
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.
0
 
Priest04Commented:
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(XMLFragment)
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.
0
 
ericamickAuthor Commented:
Here's the rest of the code, I think.
dataset.txt
form.txt
0
 
Priest04Commented:
you should basically delete questions, since the post doesn't contain the actual answer, if someone else has the same problem. :)
0
 
Priest04Commented:
you should basically delete question, since the post doesn't contain the actual answer, if someone else has the same problem. :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.