Ok, I'm not really sure how to do this (I'm very very new) but I want to add specific items to a checkbox based on the what the user selects in the listbox.
So lets say user choses "Item" from the listbox, from that selection the checkbox is filled with "Upgrade item 1" "Upgrade item 2" ect.
How would I go about doing this? I've been searching but haven't quite found it yet so I figured I would ask.
Listbox to Checkbox
Started by Christoph, Jul 18 2009 05:33 PM
11 replies to this topic
#1
Posted 18 July 2009 - 05:33 PM
|
|
|
#2
Posted 19 July 2009 - 02:45 AM
What are you using? VB6? VB.NET?
#3
Posted 19 July 2009 - 10:09 AM
VB .NET
#4
Posted 19 July 2009 - 10:26 AM
If I understood you right you want to get the text of the item the user selected. Take that text and put it to some checkboxes with "Upgrade" in front of it and a number after it.
If I understood it right you can do it like this:
In this example the listbox is called: ListBox1 and the checkboxes is called: CheckBox1, CheckBox2 and CheckBox3 but I recommend to change it.
If I understood it right you can do it like this:
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged If ListBox1.SelectedIndex <> -1 Then CheckBox1.Text = "Upgrade " & ListBox1.Items(ListBox1.SelectedIndex) & " 1" CheckBox2.Text = "Upgrade " & ListBox1.Items(ListBox1.SelectedIndex) & " 2" CheckBox3.Text = "Upgrade " & ListBox1.Items(ListBox1.SelectedIndex) & " 3" End If End Sub
In this example the listbox is called: ListBox1 and the checkboxes is called: CheckBox1, CheckBox2 and CheckBox3 but I recommend to change it.
#5
Posted 19 July 2009 - 10:41 AM
Well, not exactly.
Basically what I'm looking for is when the user selects a certain item in the list box it fills the checkbox with upgrades that can be added to that item they chose in the list box. And from there they can select the upgrades that they want for the item selected from the listbox.
The upgrades are completely different items than what is selected in the list box. And all the upgrades will be listed in one checkbox not multiple ones.
Not sure I'm explaining it right but hopefully that makes sense.
Basically what I'm looking for is when the user selects a certain item in the list box it fills the checkbox with upgrades that can be added to that item they chose in the list box. And from there they can select the upgrades that they want for the item selected from the listbox.
The upgrades are completely different items than what is selected in the list box. And all the upgrades will be listed in one checkbox not multiple ones.
Not sure I'm explaining it right but hopefully that makes sense.
#6
Posted 19 July 2009 - 10:54 AM
Are you sure you mean checkbox? because it doesn't sounds like one.
#7
Posted 19 July 2009 - 10:57 AM
I think I figured out what I'm talking about doing
Say they select the first item from the listbox (0 is actually a descriptor of a section in the listbox not an actual item)
That actually seems to do what I am looking to do. Don't know if it's the right way to do it but it definitely works how I want it to :) And basically I'll be going through the list to add different upgrade items to the rest of the stuff listed in the listbox.
Say they select the first item from the listbox (0 is actually a descriptor of a section in the listbox not an actual item)
If lstModels.SelectedIndex = 1 Then
ckUpgrades.Items.Clear()
ckUpgrades.Items.AddRange(New Object() {"Upgrade Item 1", "Upgrade item 2"})
End If
That actually seems to do what I am looking to do. Don't know if it's the right way to do it but it definitely works how I want it to :) And basically I'll be going through the list to add different upgrade items to the rest of the stuff listed in the listbox.
#8
Posted 19 July 2009 - 11:00 AM
But a checkbox doesn't have items...
#9
Posted 19 July 2009 - 11:05 AM
Ok.. well that's odd. Because it added all the items to the checkbox and I pulled the code out of what VB generated for me by adding items via the properties window.
Also I have to double click to put a check mark in the box.. very odd.
Also I have to double click to put a check mark in the box.. very odd.
#10
Posted 19 July 2009 - 11:07 AM
You maybe means a CheckedListBox. If this is the case, to check a box the correct item needs to be selected first.
EDIT: I see you edited the post, did it work now?
EDIT: I see you edited the post, did it work now?
#11
Posted 19 July 2009 - 11:09 AM
Yes, sorry! I am using a checked list box :o And yes, it does work properly, I just didn't realize you had to have the item selected first to be able to check it.
#12
Posted 19 July 2009 - 11:11 AM
Don't worry about that, I'm glad it worked :D


Sign In
Create Account


Back to top









