Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 288
  • Last Modified:

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.
0
ericamick
Asked:
ericamick
  • 5
  • 5
1 Solution
 
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
 
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
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
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
 
ericamickAuthor 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 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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now