How To Do A Listbox Array VB.Net

SOLVED Discussion in 'Web Design & Coding' started by Comptech, Dec 13, 2011.

  1. Comptech

    Comptech ICT Technican

    Joined:
    Dec 11, 2011
    Messages:
    16
    Location:
    UK
    If you need to ever do a listbox as a refrance and click on each item and take you to a next page the following code on a click event is what you are looking for,

    Code under clicker event ie button or radio button checkbox or whatever



    Code,

    Dim questions As Form() = New Form() {Form2, Me, Form2, Me}
    questions(0) = Form2

    questions(CheckedListBox1.SelectedIndex).Show()

    ------------------------------------------------------------------------------------------------

    Dim question as form() = new form() {form2,Me "add each for into that section"

    questions(0) = Form2 "Put the oder of the listbox you want it displayed in"


    example

    Listbox starts with 0 so the first array would be set to 0 like the above sample



    questions(CheckedListBox1.SelectedIndex).Show() "This peace of code tells the computer the display the page if that is the seledted index"


    Hope this helps

    Kind Regards

    Bradley
     
    Last edited: Dec 13, 2011
    Comptech, Dec 13, 2011
    #1
    Zeus likes this.
    1. Advertisements

  2. Comptech

    AceInfinity Somewhere...

    Joined:
    Aug 13, 2012
    Messages:
    7
    Location:
    Canada
    Code:
    Dim questions As Form() = New Form() {Form2, Me, Form2, Me}
    You're just extending the Form array by 2 elements when you add Form2 twice and Me (the main form presumably) twice. Which is not needed, there's no purpose for that. :)

    Code:
    questions(0) = Form2
    Then setting the first element of this array to the element that it already represents, also not necessary.

    If I may rephrase this? :)

    "Listbox elements start at index 0, so the first element would represent index 0"

    You're not setting the array to 0, you're retriving the first element of the Form array to either get or set that element within the index at 0...

    I can't see what you're trying to do here though, some of the code you have is confusing and no offence, makes no sense.

    If you want to show the form from the array of Form's, based on the CheckedListBox SelectedIndex, then this is really all you need. I'm not sure what the purpose of having a CheckedListBox over a regular ListBox is though.

    Code:
    Dim questions As Form() = New Form() {Me, Form2}
    questions(CheckedListBox1.SelectedIndex).Show()
    However, this also means that you require at least 2 ListBox items in order for this to work properly, and no more, and one other thing, you should be checking for IF a ListBox item is selected, otherwise if this code goes into the wrong event Sub, or is called based on the wrong conditions, then having no items selected will return a value of -1.

    You can't index that within an Array. the IndexOf method returns -1 when a specific searched element is not found, but otherwise you'll have an error on your hands.

    Code:
    If CheckedListBox1.SelectedIndex <> -1 Then
    	Dim questions As Form() = New Form() {Me, Form2}
    	questions(CheckedListBox1.SelectedIndex).Show()
    End If
     
    AceInfinity, Aug 13, 2012
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robert Stringer

    Innovision AP-1680 Won't boot striped raid array

    Robert Stringer, Sep 11, 2003, in forum: DIY Computers
    Replies:
    0
    Views:
    409
    Robert Stringer
    Sep 11, 2003
  2. Robert Bailey

    Raid array problems

    Robert Bailey, Feb 5, 2004, in forum: DIY Computers
    Replies:
    8
    Views:
    474
    Philip Jones
    Feb 8, 2004
  3. anthonyi

    New Mobo, Transfer RAID0 Array?

    anthonyi, Apr 25, 2004, in forum: DIY Computers
    Replies:
    2
    Views:
    411
    anthonyi
    Apr 26, 2004
  4. Jonathan Eales

    Amazing RAID array performance

    Jonathan Eales, Oct 20, 2004, in forum: DIY Computers
    Replies:
    19
    Views:
    819
    Philip Jones
    Oct 26, 2004
  5. GSV Three Minds in a Can

    Re: Onboard RAID died. Can I rebuilt the array?

    GSV Three Minds in a Can, Oct 14, 2005, in forum: DIY Computers
    Replies:
    0
    Views:
    300
    GSV Three Minds in a Can
    Oct 14, 2005
  6. Jaimie Vandenbergh

    Re: Onboard RAID died. Can I rebuilt the array?

    Jaimie Vandenbergh, Oct 14, 2005, in forum: DIY Computers
    Replies:
    2
    Views:
    278
    Trevor Best
    Oct 15, 2005
  7. Mike Halmarack

    Moving program files off RAID array and de-RAIDING

    Mike Halmarack, Oct 28, 2005, in forum: DIY Computers
    Replies:
    18
    Views:
    530
    Mike Halmarack
    Oct 30, 2005
  8. Nick O'Tyme
    Replies:
    0
    Views:
    1,505
    Nick O'Tyme
    Feb 19, 2008
Loading...