How To Do A Array For A Listview Table

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

  1. Comptech

    Comptech ICT Technican

    Joined:
    Dec 11, 2011
    Messages:
    16
    Likes Received:
    14
    Location:
    UK
    This is how to do an array for a fist view table in a table view or click event

    same as the listvbox but the show states diffrent slightly

    A bing thanks to dreamincode for there help with this peace of code

    Code;

    Dim questions As Form() = New Form() {Form2, Me, Form2, Me}
    questions(0) = Form2
    questions(1) = Form3
    questions(ListView1.SelectedIndices.Item(0)).Show()

    Kind Regards

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

  2. Comptech

    AceInfinity Somewhere...

    Joined:
    Aug 13, 2012
    Messages:
    7
    Likes Received:
    0
    Location:
    Canada
    You're storing more bytes in memory than needed for no reason here:
    Code:
    Dim questions As Form() = New Form() {Form2, Me, Form2, Me}
    Should be:
    Code:
    Dim questions As Form() = New Form() {Me, Form2}
    I notice you later try to change one of the array elements to Form3, and one to Form2, which is already an element that holds the Form2 object.

    Code:
    questions(0) = Form2
    questions(1) = Form3
    After that code gets executed, your array now looks like this:
    Code:
    Dim questions As Form() = New Form() {Form2, Form3, Form2, Me}
    With 2 Form2 elements, which is unnecessary here.

    If you come back to these threads hopefully you'll learn what you're actually doing here as I don't think you completely understand what you're doing with the assignment operator when you index an array element and give it a Form value....

    One very bad thing about what you're doing here, is you're assuming based on your code that there is at least one selected item in the ListView.

    (This is a no no)

    Provide logic to check. Also look at the way I give the array the elements I want it to have right away:
    Code:
    If ListView1.SelectedIndices.Count > 0 Then
    	Dim questions As Form() = New Form() {Me, Form2, Form3}
    	Dim index As Integer = ListView1.SelectedIndices(0)
    	If index < questions.Length Then
    		questions(ListView1.SelectedIndices(0)).Show()
    	End If
    End If
    Another thing in my code to take note of, I check the Integer value of the first selected index in ListView1, because if it's greater than the index which represents the last index in the array of Form... questions... Then you'll receive an IndexOutOfRange Exception.
     
    Last edited: Aug 13, 2012
    AceInfinity, Aug 13, 2012
    #2
    1. Advertisements

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. SwordWielder

    Learning XHTML.. how do I make a box/table?

    SwordWielder, Aug 31, 2003, in forum: Web Design & Coding
    Replies:
    4
    Views:
    2,169
    James
    Sep 4, 2003
  2. S Walch

    gap between Table and Table Cell

    S Walch, Dec 17, 2004, in forum: Web Design & Coding
    Replies:
    3
    Views:
    1,704
    D Schrute
    Dec 17, 2004
  3. Stubworth

    How to display user table contents!

    Stubworth, Nov 15, 2005, in forum: Web Design & Coding
    Replies:
    6
    Views:
    1,337
    James
    Nov 20, 2005
  4. k3o

    Table expanding help

    k3o, Feb 25, 2006, in forum: Web Design & Coding
    Replies:
    10
    Views:
    1,620
  5. S Walch

    Highlight table cells with a background Image

    S Walch, Apr 27, 2006, in forum: Web Design & Coding
    Replies:
    8
    Views:
    1,405
    S Walch
    Apr 27, 2006
  6. Albert Fish

    Recent Graphics Card League Table ?

    Albert Fish, Sep 23, 2003, in forum: DIY Computers
    Replies:
    14
    Views:
    1,111
    Ross Tregaskis
    Sep 24, 2003
  7. Alex
    Replies:
    0
    Views:
    501
  8. Comptech

    SOLVED How To Highlight The 1St Row in A Listview VB.net

    Comptech, Dec 12, 2011, in forum: Web Design & Coding
    Replies:
    1
    Views:
    3,718
    AceInfinity
    Aug 13, 2012
Loading...