I think what I am trying to do should be simple but I can't seem to find the answer
I have an UltraWinGrid with two bands. I am using a BindingSource that uses a Binding List of one object type (Band 0) that has a property that is a BindingList of a second object type(Band 1). I am able to sort the first band records by declaring the sorting rules in the Sort property of the binding source.
But I also need to sort the Band1 objects by a property of that object type. Can I do this in the Grid properties? What is the property I am looking for? This just needs to be a one-time sort. It won't change and the user cannot change the sorting via the UI.
I have looked at implementing a SortableBindingList extension but I just can't help but think there is an easier way to do this.
Can anyone help?
I'm not sure how (or if) you can do this on the BindingList.
In the grid you can sort by setting the SortIndicator property on a column. I would recommend that you do this in the InitializeLayout event of the grid.
This will display a SortIndicator on the column header and unfortunately, there's no property to disable sorting by the user and still sort the data programmatically.
But what you can do is handle the BeforeSortChange event and cancel it. So the code would look like this:
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { e.Layout.Bands[1].Columns["column key"].SortIndicator = SortIndicator.Ascending; } private void ultraGrid1_BeforeSortChange(object sender, BeforeSortChangeEventArgs e) { e.Cancel = true; }
Meh. Not very elegant but it works.
Thanks for the help.
JP
Yes. There's a RefreshSortPosition method on the row - so you can re-sort a single row into it's property place.
Or you can call band.SortedColumns.RefreshSort() to sort the entire band at once.
So one more addendum to this question... Now I am adding objects to my BindingList at the 0 Band level and they are appearing at the bottom of the grid instead of being inserted within the sorted order I intitialized the grid with. Is there a good way to re-apply the sorting rules like I did at first?
jpaull42 said:Not very elegant but it works.
I agree. :)
If you like, you can Submit a feature request to Infragistics and perhaps the ability to sort and disable user sorting can be adding in a future release.