Solved

ComboBoxes accepting the same values?

Posted on 2014-04-11
4
199 Views
Last Modified: 2014-04-11
I have 2 combobox controls that are loaded via a DataTable. Both CB's use the same DataTable to load them. However, prior to loading I assign the DataTable to a newly created DataTable. I'm loading these CB's with the same values, however, each one could contain a different selected value.

My problem is that when I select a value from one, the other CB automatically reflects the same value, why is that and how can that be resolved...other than creating a new routine as a separate load.

Here is my code:

    Public Sub LoadCombo_Direction()
        Try
            Dim ds As New DataSet

            InitializeErrorClass(EH)
            BL.LoadCombo_Direction(EH)

            cmbDirection1.DataSource = Nothing
            cmbDirection2.DataSource = Nothing

            If EH.DataSet.Tables(0).Rows.Count > 0 Then
                ds = EH.DataSet

                RemoveHandler cmbDirection1.SelectedIndexChanged, AddressOf cmbDirection1_SelectedIndexChanged
                cmbDirection1.DisplayMember = EH.DataSet.Tables(0).Columns(1).ColumnName
                cmbDirection1.ValueMember = EH.DataSet.Tables(0).Columns(0).ColumnName
                cmbDirection1.DataSource = EH.DataSet.Tables(0)
                cmbDirection1.SelectedIndex = -1

                cmbDirection2.DisplayMember = ds.Tables(0).Columns(1).ColumnName
                cmbDirection2.ValueMember = ds.Tables(0).Columns(0).ColumnName
                cmbDirection2.DataSource = ds.Tables(0)
                cmbDirection2.SelectedIndex = -1
                AddHandler cmbDirection1.SelectedIndexChanged, AddressOf cmbDirection1_SelectedIndexChanged
            End If

        Catch ex As Exception
            EH.ErrorMessage = "LoadCombo_Direction() - " & ex.Message & "~E"
        End Try

        EH.ProcessMessages(Me, sbr, EH.ErrorMessage)
    End Sub

Open in new window

0
Comment
Question by:BlakeMcKenna
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 39995363
Change this line

ds = EH.DataSet

to

ds = EH.DataSet.Copy()
0
 

Author Comment

by:BlakeMcKenna
ID: 39995370
That worked CodeCruiser but what essentially was happening with the way I was doing it?
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39995402
You were just copying the reference of the same dataset into the new variable(so 2 variables pointing to the same object in memory) instead of creating a real copy of it.
0
 

Author Comment

by:BlakeMcKenna
ID: 39995424
Got it...thanks for the clarification!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question