Question : Datagrid and Arraylist in VB.Net

Hi,

I am binding an arraylist to a datagrid in VB.Net. The arraylist contains objects of class data_container(see code below). These are the following features I need to incorporate:

1. Add  and delete rows from the datagrid.
2. Be able to copy from an excel sheet to the datagrid. The program should be able figure out the number of rows that are being pasted and expand the datagrid accordingly.

Is datagrid the best approach to implement the above features? Due to existing design, I must use arraylists.
If so, how can I implement the above required features?

Also, when I display the datagrid, the fields are displayed in alphabetical order. For example, my fields are name, code and location and this is the order I want them to be displayed  in the datagrid. However, the fields are displayed as code, location and name. How can I override this and display the fields in an order I want?

Thanks very much,
Pratibha

*************************************Code Snippet********************************
 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

      Dim data_arraylist As New ArrayList
       Dim i As Integer

      For i = 0 To 5
            Dim data_container_obj As data_container
            data_arraylist.Add(New data_container("prat", 2, "Loc1"))
      Next
     
     DataGrid1.DataSource = data_arraylist

end sub

=============================

'data_container class:

Public Class data_container
    Private m_name As String
    Private m_code As Integer
    Private m_location As String


    Public Sub New(ByVal name, ByVal code, ByVal location)
        m_name = name
        m_code = code
        m_location = location
    End Sub
    Public Sub New()

    End Sub
    Public Property name() As String
        Get
            Return m_name
        End Get
        Set(ByVal Value As String)
            m_name = Value
        End Set
    End Property
    Public Property code() As String
        Get
            Return m_code
        End Get
        Set(ByVal Value As String)
            m_code = Value
        End Set
    End Property
    Public Property location() As String
        Get
            Return m_location
        End Get
        Set(ByVal Value As String)
            m_location = Value
        End Set
    End Property

End Class


Answer : Datagrid and Arraylist in VB.Net

check this
http://www.syncfusion.com/faq/winforms/search/818.asp
http://www.syncfusion.com/faq/winforms/Files/datagridarraylist.zip
Random Solutions  
 
programming4us programming4us