Results 1 to 6 of 6

Thread: [RESOLVED] How do I make my checkedlistbox value change by selection of combox value?

  1. #1

    Thread Starter
    Hyperactive Member simpleonline1234's Avatar
    Join Date
    Mar 2010
    Posts
    322

    Resolved [RESOLVED] How do I make my checkedlistbox value change by selection of combox value?

    I know that sounds strange but I came across this website today that uses this ability and I've been going nuts trying to figure out how they do it.

    The website is hxxp://search.reel-scout.com/

    Also here is a screenshot of the options I am speaking of



    There is a combolistbox that has a list of topics.

    Depending on what topic you choose will determine what checklistbox option will appear in the check list box.

    What are they doing there to create that option? I was thinking that maybe they created 20 checkedlistboxes and then if the selection of the combolistbox is "THIS" then they set the getfocus to that checkedlistbox but that didn't quite work for me.

    any idea?

    Thanks
    Are you down with OOP?

  2. #2
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,401

    Re: How do I make my checkedlistbox value change by selection of combox value?

    How do you populate a listview in the first place? it's the same just depending on whats selected.

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: How do I make my checkedlistbox value change by selection of combox value?

    you'd use a dataset with parent/child tables + a datarelation + databinding:

    here's an example:

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4.         'create a new dataset
    5.         Dim ds As New DataSet
    6.  
    7.         'create the parent table + add a column
    8.         Dim dt As New DataTable("parent")
    9.         dt.Columns.Add("type")
    10.  
    11.         'add 2 items to the parent table "type" column
    12.         dt.Rows.Add(New Object() {"Type1"})
    13.         dt.Rows.Add(New Object() {"Type2"})
    14.  
    15.         'add the table to the dataset
    16.         ds.Tables.Add(dt)
    17.  
    18.         'create the child table + add 2 columns
    19.         dt = New DataTable("child")
    20.         dt.Columns.Add("type")
    21.         dt.Columns.Add("item")
    22.  
    23.         'add 10 items to the child table
    24.         For x As Integer = 1 To 5
    25.             dt.Rows.Add(New Object() {"Type1", "Type1 Item" & x.ToString})
    26.         Next
    27.         For x As Integer = 1 To 5
    28.             dt.Rows.Add(New Object() {"Type2", "Type2 Item" & x.ToString})
    29.         Next
    30.  
    31.         'add the table to the dataset
    32.         ds.Tables.Add(dt)
    33.  
    34.         'create the datarelation
    35.         ds.Relations.Add("relation1", ds.Tables("parent").Columns("type"), ds.Tables("child").Columns("type"), True)
    36.  
    37.         'create a new BindingSource to bind the ComboBox to the parent table
    38.         Dim bs1 As New BindingSource(ds, "parent")
    39.         ComboBox1.DisplayMember = "type"
    40.         ComboBox1.DataSource = bs1
    41.  
    42.         'create a new BindingSource to bind the CheckedListBox to the filtered child table
    43.         Dim bs2 As New BindingSource(bs1, "relation1")
    44.         CheckedListBox1.DataSource = bs2
    45.         CheckedListBox1.DisplayMember = "item"
    46.  
    47.     End Sub
    48.  
    49. End Class

  4. #4
    Member Aggierich's Avatar
    Join Date
    Oct 2011
    Posts
    32

    Re: How do I make my checkedlistbox value change by selection of combox value?

    I had this same problem a lil while back when i was tryin to change listbox based on combobox.text value. Here's how I worked around it:

    Code:
    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ListBox1.Visible = False
            ListBox2.Visible = False
            ListBox3.Visible = False
        End Sub
    
        Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
            ' Display ListBox1 When ComboBox1.Text is set to "Resturants"
            If ComboBox1.Text = "Resturants" Then
                ListBox1.Visible = True
                ListBox2.Visible = False
                ListBox3.Visible = False
            End If
            ' Display ListBox2 When ComboBox1.Text is set to "Stores"
            If ComboBox1.Text = "Stores" Then
                ListBox1.Visible = False
                ListBox2.Visible = True
                ListBox3.Visible = False
            End If
            ' Display ListBox3 When ComboBox1.Text is set to "Gas Stations"
            If ComboBox1.Text = "Gas Stations" Then
                ListBox1.Visible = False
                ListBox2.Visible = False
                ListBox3.Visible = True
            End If
        End Sub
    
       
    End Class

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: How do I make my checkedlistbox value change by selection of combox value?

    Quote Originally Posted by Aggierich View Post
    I had this same problem a lil while back when i was tryin to change listbox based on combobox.text value. Here's how I worked around it:

    Code:
    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ListBox1.Visible = False
            ListBox2.Visible = False
            ListBox3.Visible = False
        End Sub
    
        Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
            ' Display ListBox1 When ComboBox1.Text is set to "Resturants"
            If ComboBox1.Text = "Resturants" Then
                ListBox1.Visible = True
                ListBox2.Visible = False
                ListBox3.Visible = False
            End If
            ' Display ListBox2 When ComboBox1.Text is set to "Stores"
            If ComboBox1.Text = "Stores" Then
                ListBox1.Visible = False
                ListBox2.Visible = True
                ListBox3.Visible = False
            End If
            ' Display ListBox3 When ComboBox1.Text is set to "Gas Stations"
            If ComboBox1.Text = "Gas Stations" Then
                ListBox1.Visible = False
                ListBox2.Visible = False
                ListBox3.Visible = True
            End If
        End Sub
    
       
    End Class
    i wouldn't recommend that. it works but it's an unnecessary drain on resources

  6. #6

    Thread Starter
    Hyperactive Member simpleonline1234's Avatar
    Join Date
    Mar 2010
    Posts
    322

    Re: How do I make my checkedlistbox value change by selection of combox value?

    Hey thanks Paul and others....your solutions have saved the day...sorry for the delayed response....been coding like crazy to get this app up....eyes are burning so I took a break but any who...thanks guys you rock!
    Are you down with OOP?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width