Solved

combo box value changed

Posted on 2004-09-22
1
238 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 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

21 Experts available now in Live!

Get 1:1 Help Now