Results 1 to 10 of 10

Thread: VB.NET: Question on presenting array

  1. #1

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230

    VB.NET: Question on presenting array

    If i have a list of arrays, how to go about viewing every individual of it...

    Say inside each of the array has this content:

    Name: OO
    Age: XX

    how to you guys present the dynamic arrays or arrays on one form in your Window application......

    Thanks
    Last edited by toytoy; Sep 28th, 2004 at 10:16 AM.

  2. #2
    Addicted Member rdove's Avatar
    Join Date
    Dec 2002
    Location
    Indianapolis
    Posts
    251

    Re: VB.NET: Question on presenting array

    Originally posted by toytoy
    If i have a list of arrays, how to go about viewing every individual of it...

    Say inside each of the array has this content:

    Name: OO
    Age: XX

    how to you guys present the dynamic arrays or arrays on one form in your Window application......

    Thanks
    huh?

    Do you mean you want to display the contents of an array?

    Code:
    Dim i as Integer
    Dim Array(2) as String
    
    Array(0) = "Name: OO"
    Array(1) = "Age: XX"
    
    For i = 0 to UBound(Array)
      Console.Writeline(Array(i)
    Next
    ~Ryan





    Have I helped you? Please Rate my posts.

  3. #3

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230
    Some sort of this....but display all at the same time in listbox..

    is it possible...

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Then use ListBox1.Items.Add() instead of Console.WriteLine

  5. #5

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230
    cannot...

    it is ok if i am using listbox to display....

    but say i want to selected from one block of array..

    the listbox can only select either the name or age..

    it cannot select both name and age together..

    any other control can i use to display and then select from it..

    Thanks
    Last edited by toytoy; Sep 29th, 2004 at 02:05 AM.

  6. #6
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    i don't quiet get what you mean but does this help?
    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Dim i As Integer
    3.         Dim p() As person = {New person("toytoy", 10), New person("mendhak", 12)}
    4.         For i = 0 To UBound(p)
    5.             ListBox1.Items.Add(p(i).name & " " & p(i).age.ToString())
    6.         Next
    7.     End Sub
    8.  
    9.     Structure person
    10.         Dim name As String
    11.         Dim age As Integer
    12.         Sub New(ByVal name As String, ByVal age As Integer)
    13.             Me.name = name
    14.             Me.age = age
    15.         End Sub
    16.     End Structure
    Last edited by brown monkey; Sep 29th, 2004 at 02:19 AM.

  7. #7
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: VB.NET: Question on presenting array

    Originally posted by toytoy
    If i have a list of arrays, how to go about viewing every individual of it...

    Say inside each of the array has this content:

    Name: OO
    Age: XX

    how to you guys present the dynamic arrays or arrays on one form in your Window application......

    Thanks
    It is only the final rank of an array which can be used to store data. So, you will either have to have multiple elements in the final rank or do as brown monkey posted and use a structure (or a custom class ).

    You can then loop through the array, extracting and concanting the information you require and adding it to the listbox. You can loop through the array in as many segments as you require, e.g. one at a time; blocks of five at a time or the whole lot.

    I have assumed that what you meant in your final post was that you want to select both name and age simultaneously.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  8. #8

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230

    VB.NET: How to arrange the listbox display using XmlDocument

    But what if i want to use XmlDocument and extract the nodes to create an arraylist in the listbox...

    Say i use XmlDocument Method to select the nodes...


    Code:
    For Each n In xdoc.SelectNodes("//Book/Title")
    a = "Author : " & n.Attributes("Author").Value
    lst3.Items.Add(a)
    Next
    
    For Each n In xdoc.SelectNodes("//Book/Title")
    b = "Date : " & n.Attributes("Date").Value 
    lst3.Items.Add(b)
    Next
    How to arrange the list box to appear like below after i add the items to it

    Peter
    10/2/04
    ------------
    John
    11/2/04
    -------------

    instead of

    Peter
    John
    10/2/04
    112/04

    is it possible....

    Thanks
    Last edited by toytoy; Dec 3rd, 2004 at 08:07 AM.

  9. #9
    Addicted Member rdove's Avatar
    Join Date
    Dec 2002
    Location
    Indianapolis
    Posts
    251
    Can't you just do it like this?

    Code:
    For Each n In xdoc.SelectNodes("//Book/Title")
      a = "Author : " & n.Attributes("Author").Value
      b = "Date : " & n.Attributes("Date").Value 
      lst3.Items.Add(a)
      lst3.Items.Add(b)
      lst3.Items.Add("-------------")
    Next
    Or are you wanting it to show up like that and be the same selected item index?

    If thats the case, I don't believe you can hve multiple lines with the same index.

    You would have to display the data like:

    Code:
    For Each n In xdoc.SelectNodes("//Book/Title")
      a = "Author : " & n.Attributes("Author").Value
      b = "Date : " & n.Attributes("Date").Value 
      lst3.Items.Add(a & " - " & b)
    Next
    Last edited by rdove; Sep 29th, 2004 at 12:06 PM.
    ~Ryan





    Have I helped you? Please Rate my posts.

  10. #10

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230
    But what if more than one nodes is select using
    Code:
    doc.SelectNodes("//Book/Title/Page")
    doc.SelectNodes("//Book/Title")
    can it be achieve also...
    Last edited by toytoy; Dec 3rd, 2004 at 08:07 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width