Binding business object (arraylist) with datagrid

Posted on 2006-04-28
Last Modified: 2013-11-15
I have one business class

   Public Class Firm
        Dim _FirmID As Integer
        Dim _FirmName As String
        Public Property FirmID() As Integer
                Return _FirmID
            End Get
            Set(ByVal value As Integer)
                _FirmID = value
            End Set
        End Property
        Public Property FirmName() As String
                Return _FirmName
            End Get
            Set(ByVal value As String)
                _FirmName = value
            End Set
        End Property
End Class
i am binding arraylist of objFirms - i am able to bind it. BUT question is sequence of fields are not correctly displayed in datagrid. i grid they are displayed like following

1. Firmname 2. FirmID

Question by:innominds
    LVL 2

    Expert Comment

    You have to sort the array before you bind it.  However there is no way to tell how your class Firm is ordering.  Therefore you have to implement your own comparison function, e.g.

    Class Firm : System.Collection.IComparer
      public int Compare(object x, object y)
         // write your comparison result here

    After that, you can use the sort function, e.g.

    ArrayList a = new ArrayList();
    ... // add your firm class here



    Author Comment

    i am not talking about record sorting but column sequence (firm id should come first then firm name should come)

    LVL 2

    Accepted Solution

    Opps sorry, if you want to have a specific ordering for the column, you must disable the auto generating columns and manually add the columns, e.g.

    Dim dg as new DataGrid
    dg.AutoGenerateColumns = false

    Dim Column1 as new BoundColumn()
    Column1.DataField = "FirmID"

    Dim Column2 as new BoundColumn()
    Column2.DataField = "FirmName"

    ' Thereafter, bind you datagrid...

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Suggested Solutions

    Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
    If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now