|
-
Nov 3rd, 2011, 03:58 PM
#1
Thread Starter
Hyperactive Member
[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
-
Nov 3rd, 2011, 04:12 PM
#2
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.
-
Nov 3rd, 2011, 04:35 PM
#3
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:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'create a new dataset
Dim ds As New DataSet
'create the parent table + add a column
Dim dt As New DataTable("parent")
dt.Columns.Add("type")
'add 2 items to the parent table "type" column
dt.Rows.Add(New Object() {"Type1"})
dt.Rows.Add(New Object() {"Type2"})
'add the table to the dataset
ds.Tables.Add(dt)
'create the child table + add 2 columns
dt = New DataTable("child")
dt.Columns.Add("type")
dt.Columns.Add("item")
'add 10 items to the child table
For x As Integer = 1 To 5
dt.Rows.Add(New Object() {"Type1", "Type1 Item" & x.ToString})
Next
For x As Integer = 1 To 5
dt.Rows.Add(New Object() {"Type2", "Type2 Item" & x.ToString})
Next
'add the table to the dataset
ds.Tables.Add(dt)
'create the datarelation
ds.Relations.Add("relation1", ds.Tables("parent").Columns("type"), ds.Tables("child").Columns("type"), True)
'create a new BindingSource to bind the ComboBox to the parent table
Dim bs1 As New BindingSource(ds, "parent")
ComboBox1.DisplayMember = "type"
ComboBox1.DataSource = bs1
'create a new BindingSource to bind the CheckedListBox to the filtered child table
Dim bs2 As New BindingSource(bs1, "relation1")
CheckedListBox1.DataSource = bs2
CheckedListBox1.DisplayMember = "item"
End Sub
End Class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 3rd, 2011, 04:40 PM
#4
Member
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
-
Nov 3rd, 2011, 04:49 PM
#5
Re: How do I make my checkedlistbox value change by selection of combox value?
 Originally Posted by Aggierich
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 3rd, 2011, 08:29 PM
#6
Thread Starter
Hyperactive Member
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!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|