CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2004
    Location
    India
    Posts
    8

    Arraylist in a datagrid

    Hi ,

    I have a bounded column in my datagrid which is an arraylist.while saving to the grid on a button click ,i am getting system.collection.arraylist , instead of the actual values in the arraylist.Could anybody please tell me how to display the values in the arraylist in the datagrid.My code is as follows:
    Dim dtb New DataTable
    Dim arl As New ArrayList
    Dim drow As DataRow
    Dim intcount as Integer

    dtb= Get_Datatable(mydatagrid)

    drow = dtb.NewRow

    For intCount = 0 To mylisbox.listbox.ListItems.Count - 1
    arl.Add(mylistbox.ListItems(intCount).Value)
    Next
    drow("ArrayList") = arl
    dtb.Rows.Add(drow)

    dtb.AcceptChanges()

    mydatagrid.DataSource = dtb
    mydatagrid.DataBind()


    Note :Get_Datatable() is a function that will return the datatable of the datagrid

    Thanks and Regards
    Dhanya

  2. #2
    Join Date
    Feb 2005
    Location
    Israel
    Posts
    1,475

    Re: Arraylist in a datagrid

    You are mixing an ArrayList with a DataTable. I don't think you can do what you are trying, but maybe there is a way. I don't know.
    I suggest an alternative way. Use a DataSet with two DataTables and a DataRelation between them. This will work very well. To simulate this behavior with an ArrayList seems impossible.

  3. #3
    Join Date
    Dec 2004
    Location
    India
    Posts
    8

    Re: Arraylist in a datagrid

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

    Hi ,

    I have a bounded column in my datagrid which is an arraylist.while saving to the grid on a button click ,i am getting system.collection.arraylist , instead of the actual values in the arraylist.Could anybody please tell me how to display the values in the arraylist in the datagrid.My code is as follows:
    Dim dtb New DataTable
    Dim arl As New ArrayList
    Dim drow As DataRow
    Dim intcount as Integer

    dtb= Get_Datatable(mydatagrid)

    drow = dtb.NewRow

    For intCount = 0 To mylisbox.listbox.ListItems.Count - 1
    arl.Add(mylistbox.ListItems(intCount).Value)
    Next
    drow("ArrayList") = arl
    dtb.Rows.Add(drow)

    dtb.AcceptChanges()

    mydatagrid.DataSource = dtb
    mydatagrid.DataBind()


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

    i got a replay like this ,But i dont know how to create a dataset with to datatable and make relation can anybody give some example ,hoe to create it

    You are mixing an ArrayList with a DataTable. I don't think you can do what you are trying, but maybe there is a way. I don't know.
    I suggest an alternative way. Use a DataSet with two DataTables and a DataRelation between them. This will work very well. To simulate this behavior with an ArrayList seems impossible.



    thanks and regards
    Dhanya

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

Featured