DataGrid sorts all but first row

  • Thread starter Thread starter jib
  • Start date Start date
J

jib

Hi,

It is simple enough to implement column sorting on a DataGrid, but what to
do if I want all but the first row to be part of the sort? I want my sorting
algorithm to operate as expected on all rows but the first one should stay
put under all conditions. Any idea how to do this with a single DataGrid?

Thanks,

Jib
 
Hi jib,

You might add a column to your datasource with such order that the first
column stays on the first place.
 
Hi Jib,

Well, depends on what your datasource is. If you implemented IBindingList
your self, you might just ignore the sort of the first column (as well as
return no property descripter when you're being asked of what's sorted in
case you didn't sort).

check out:

IBindingList.ApplySort
IBindingList.IsSorted
IBindingList.SortDirection
IBindingList.SortProperty

if you're using a DataSet, which means you bound to a DataView a solution
could be to write a "Proxy" which I mean in this context to be a class that
implements IBindingList and ITypedList and simply forwards all call to an
inner (agregated) object which in fact is the DataView.

something like:

class MyViewWrapper : IBindingList, ITypedList {
DataView _view:

public MyViewWrapper(DataView view) {
_view = view;
}

// e.g. for the indexer:
public object this[int index] {
get {
reutn _view[index];
}
set {
_view[index] = value;
}
}
}

in advance you could kinda hook in into the sort calls and add your
behavior. The disadvantage is that you have to implement about 30 methods
even though they only forward the call to the _view-field.

note that you could use IBindingList instead of DataView to get a slightly
more flexible/generic solution.

regards

Christian
 
Back
Top