Solved

combo box value changed

Posted on 2004-09-22
1
239 Views
Last Modified: 2010-04-23
I have a function
 Sub FillComboBox(ByVal cbo As ComboBox, ByVal cmd As SqlClient.SqlCommand, ByVal sValueMem As String, ByVal sDisplayMem As String, ByVal CurrentID As Object)
        'Given a combo box, a command string, and a few other parameters, this procedure will fill the combo box with an ID and display value.

        Dim da As New SqlClient.SqlDataAdapter
        Dim ds As New DataSet

        Try
            'Clear all items from the combo box.
            cbo.DataSource = Nothing
            cbo.Items.Clear()

            'Use the local data adapter to fill the local dataset based on the Command object which was passed in.
            ds.Reset()
            da.SelectCommand = cmd
            da.Fill(ds)

            'Set value member, display member.
            'Then populate the combo box from table 0 of the local dataset.
            cbo.DataSource = ds.Tables(0)
            cbo.ValueMember = sValueMem
            cbo.DisplayMember = sDisplayMem

        Catch ex As Exception
            MsgBox("The following error occurred in the FillComboBox procedure with combo box '" & cbo.Name & "':" & vbCrLf & ex.Message)
        End Try
        'If mblnResort = True Then
        '    Exit Sub 'do not set index for resort combo
        'End If
        'Based on the CurrentID, select a value in the combobox
        cbo.SelectedIndex = -1
        If CurrentID Is DBNull.Value Then
            ' Do nothing
        ElseIf CurrentID <> -1 Then
            Try
                cbo.SelectedValue = CurrentID
            Catch ex As Exception
                cbo.SelectedIndex = -1
            End Try
        End If
        ds.Dispose()
        da.Dispose()

    End Sub

which fills every combo box that I have. Now in my form, I have a 4 tabs, where you can have the combobox state in three different tabs. what I want is if the user changes the value in either tab, updates the others.
Thia is what I've been using

Private Sub cmbState_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbState.SelectedIndexChanged
        Try
            cmbState2.Text = cmbState.Text
            cmbState3.Text = cmbState.Text
        Catch ex As Exception
            DisplayError("Combo State changed", ex)
        End Try
    End Sub
0
Comment
Question by:Ilianam
1 Comment
 
LVL 5

Accepted Solution

by:
tzxie2000 earned 500 total points
ID: 12124644
Private Sub cmbState_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbState.SelectedIndexChanged
        Try
            cmbState2.SelectedIndex=cmbState2.Items.IndexOf(cmbState.Text)
            cmbState3.SelectedIndex=cmbState3.Items.IndexOf(cmbState.Text)
        Catch ex As Exception
            DisplayError("Combo State changed", ex)
        End Try
    End Sub
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Code enhancement 5 23
Events in static methods 3 50
Exit the loop 4 37
Get the selected ValueMember of Combobox 5 21
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

867 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now