Question How databinding between 2 combobox from database

ppc493

New member
Joined
Nov 22, 2012
Messages
1
Programming Experience
Beginner
i use VB.NET Visual studio 2008.


i have 2 combobox is cbSection and cbTeam. i need databinding between 2 combobox.
when i'm select data from cbSection will be show to cbTeam.


Ex.
cbSection
Size
Color
cbTeam
-When Select "Color"
Red
Blue
Green
-When Select "Size"
Small
Medium
High


Problem:
now, i select cbSection 'Color' but on cbSection Show fields 'Size' and cbTeam is null value.


cbSection >> cbTeam
'Color' but show 'Size' >> NULL


I need On Display Output


cbSection >> cbTeam
Color >> Blue




this code:


VB.NET:
Imports System
    Imports System.Data
    Imports System.Data.Sql
    Imports System.Data.SqlClient
    Imports System.Configuration
    
        Dim appConn As String = ConfigurationManager.ConnectionStrings("connDB").ToString
    
        Dim Conn As SqlConnection = New SqlConnection(Me.appConn)
        Dim cmd As New SqlCommand
        Dim da As New SqlDataAdapter
        Dim ds As New DataSet()
    
        Public Sub showSection()
            da = New SqlDataAdapter("SELECT DISTINCT Section From Employee Order By Section", Conn)
            da.Fill(ds)
            Conn.Close()
    
            cbSection.DataSource = ds.Tables(0)
            cbSection.DisplayMember = "Section"
            cbSection.ValueMember = "Section"
            cbSection.SelectedIndex = -1
        End Sub
    
        Private Sub cbSection_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbSection.SelectedIndexChanged
            If cbSection.SelectedIndex > -1 Then
                da = New SqlDataAdapter("SELECT DISTINCT Team From Employee WHERE Section='" + cbSection.SelectedValue.ToString() + "'", Conn)
                da.Fill(ds)
                Conn.Close()
    
                cbTeam.DataSource = ds.Tables(0)
                cbTeam.DisplayMember = "Team"
                cbTeam.ValueMember = "Team"
            End If
        End Sub

Thanks For you Time. :)
 
Top Bottom