NoviceToDotNet
NoviceToDotNet

Reputation: 10815

How can I arrange column order in a grid view when I am binding it with a list object?

How to arrange column in my data grid view for windows application when I am binding it with a list type object?

In db I have 2 many queries to fetch the data so that I can not change I need to make it at form level please suggest.

Following is a small code for this

public void FillGrid(string DriverID)
{
     grdOrderByDriver.DataSource = cOrder.GetOrderDetailByDriver(int.Parse(DriverID));
     double sum = 0.0;
     SetGird();
     sum = CalculateOrderTotal(sum);
}

GetOrderDetailByDriver returns object of

BindingList<cOrder> lstOrderByDriver = new BindingList<cOrder>();

Upvotes: 0

Views: 1242

Answers (1)

Alexander Zbinden
Alexander Zbinden

Reputation: 2566

What do you mean by "arrange"?

If your intention is to change the column order, you have two possibilities:

  • change the DisplayIndex of your column
  • if your columns are autogenerated, change the order of the properties in cOrder

If by "arrange" you mean sorting, then you need to implement a SortableBindingList (since the BindingList does not support sorting) like this: http://www.codeproject.com/Articles/31418/Implementing-a-Sortable-BindingList-Very-Very-Quic

Upvotes: 1

Related Questions