Jump to content

Listbox to Checkbox

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
11 replies to this topic

#1
Christoph

Christoph

    Newbie

  • Members
  • PipPip
  • 10 posts
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.

#2
Vswe

Vswe

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 9,552 posts
What are you using? VB6? VB.NET?

#3
Christoph

Christoph

    Newbie

  • Members
  • PipPip
  • 10 posts
VB .NET

#4
Vswe

Vswe

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 9,552 posts
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:

    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
Christoph

Christoph

    Newbie

  • Members
  • PipPip
  • 10 posts
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.

#6
Vswe

Vswe

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 9,552 posts
Are you sure you mean checkbox? because it doesn't sounds like one.

#7
Christoph

Christoph

    Newbie

  • Members
  • PipPip
  • 10 posts
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)

       
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
Vswe

Vswe

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 9,552 posts
But a checkbox doesn't have items...

#9
Christoph

Christoph

    Newbie

  • Members
  • PipPip
  • 10 posts
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.

#10
Vswe

Vswe

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 9,552 posts
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?

#11
Christoph

Christoph

    Newbie

  • Members
  • PipPip
  • 10 posts
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
Vswe

Vswe

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 9,552 posts
Don't worry about that, I'm glad it worked :D