?
Solved

Binding business object (arraylist) with datagrid

Posted on 2006-04-28
5
Medium Priority
?
216 Views
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
            Get
                Return _FirmID
            End Get
            Set(ByVal value As Integer)
                _FirmID = value
            End Set
        End Property
        Public Property FirmName() As String
            Get
                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

Dharmesh
0
Comment
Question by:innominds
  • 2
3 Comments
 
LVL 2

Expert Comment

by:akumanova
ID: 16572722
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

a.Sort();

0
 

Author Comment

by:innominds
ID: 16575273
i am not talking about record sorting but column sequence (firm id should come first then firm name should come)

Dharmesh
0
 
LVL 2

Accepted Solution

by:
akumanova earned 200 total points
ID: 16620858
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"
dg,Column.Add(Column1)

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

' Thereafter, bind you datagrid...
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Introduction to Processes

839 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