Solved

combo box value changed

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET 2008 - SQL Timeout 9 49
vb.net and creating a class 5 29
VB.NET Application Installation with sqlserver 8 45
ModalPopup  question 22 36
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

679 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