none
MultiDimension Array Values from a Listbox RRS feed

  • Question

  • i have a listbox, Instead of using fixed values on my arrMultiD, i want the content of the lstAuthors to be in the array. how will i do it.

     Dim arrMultiD As String(,) = {{"John", "21", "Berlin", "Germany"}, _

                                   {"Smith", "33", "London", "UK"}, _

                                   {"Ryder", "15", "Sydney", "Australia"}, _

                                   {"Jake", "18", "Tokyo", "Japan"}, _

                                   {"Tom", "34", "Mumbai", "India"} _

                                  }

    This sample code is not working.

    dim ctr as integer

    for ctr = 0 to lstAuthors.Items.Count -1

    dim arrMultiD as string (,) = { lstAuthors.Items(ctr).ToString(), lstAuthors.Items(ctr).ToString(), lstAuthors.Items(ctr).ToString(), lstAuthors.Items(ctr).ToString()}

    next


    cal_bonjovi

    Tuesday, May 22, 2012 10:17 AM

Answers

  • Can figure it out how.. here's my code hope you could help. Instead of making arrMultiD with fixed values, i need its values to come from a listbox

    Dim arrMultiD As String(,) = {{"John", "21", "Berlin"}, {"Smith", "33", "London"}, {"Ryder", "15", "Sydney"}, {"Jake", "18", "Tokyo"}, {"Tom", "34", "Mumbai"} }
      
     Dim dt As New System.Data.DataTable()
      
       dt.Columns.Add("Name", Type.GetType("System.String"))
      dt.Columns.Add("Pages Completed", Type.GetType("System.String"))
      dt.Columns.Add("Unique Pages", Type.GetType("System.String"))
      For i As Integer = 0 To lstUniqueAuthors.Items.Count - 1
       dt.Rows.Add()
       dt.Rows(dt.Rows.Count - 1)("Name") = arrMultiD(i, 0)
       dt.Rows(dt.Rows.Count - 1)("Pages Completed") = arrMultiD(i, 1)
       dt.Rows(dt.Rows.Count - 1)("Unique Pages") = arrMultiD(i, 2)
      Next
      
      GridMultiD.DataSource = dt
      GridMultiD.DataBind()

     


    cal_bonjovi

    Tuesday, May 22, 2012 12:21 PM
  • got it. i just have to use this 

     dt.Rows(dt.Rows.Count - 1)("Name") = lstUniqueAuthors.Items(i).ToString()
      

    cal_bonjovi

    Tuesday, May 22, 2012 12:55 PM

All replies

  • You need to have a look how to use multidimensional arrays

     


    Mark Answered, if it solves your question
    Rohit Arora

    Tuesday, May 22, 2012 10:41 AM
  • Can figure it out how.. here's my code hope you could help. Instead of making arrMultiD with fixed values, i need its values to come from a listbox

    Dim arrMultiD As String(,) = {{"John", "21", "Berlin"}, {"Smith", "33", "London"}, {"Ryder", "15", "Sydney"}, {"Jake", "18", "Tokyo"}, {"Tom", "34", "Mumbai"} }
      
     Dim dt As New System.Data.DataTable()
      
       dt.Columns.Add("Name", Type.GetType("System.String"))
      dt.Columns.Add("Pages Completed", Type.GetType("System.String"))
      dt.Columns.Add("Unique Pages", Type.GetType("System.String"))
      For i As Integer = 0 To lstUniqueAuthors.Items.Count - 1
       dt.Rows.Add()
       dt.Rows(dt.Rows.Count - 1)("Name") = arrMultiD(i, 0)
       dt.Rows(dt.Rows.Count - 1)("Pages Completed") = arrMultiD(i, 1)
       dt.Rows(dt.Rows.Count - 1)("Unique Pages") = arrMultiD(i, 2)
      Next
      
      GridMultiD.DataSource = dt
      GridMultiD.DataBind()

     


    cal_bonjovi

    Tuesday, May 22, 2012 12:21 PM
  • got it. i just have to use this 

     dt.Rows(dt.Rows.Count - 1)("Name") = lstUniqueAuthors.Items(i).ToString()
      

    cal_bonjovi

    Tuesday, May 22, 2012 12:55 PM