How to make a row display always as the last row based on its cell value?
I have sorted the rows based on some column value. But there is a row which I need to display always as the last row irrespective of the sorting order. How can I do this?
Thanks.
Do you want the row at the bottom of the list? Or the bottom of the grid?
If you want to have a fixed row at the bottom of the grid, you would do something like this:
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { e.Layout.Override.FixedRowStyle = FixedRowStyle.Bottom; }
Then you just set the Fixed property on the row you want. The InitializeRow event would be a good place to set this.
If you just want the row to always be last in the sort order, then you would have to use a custom SortComparer on the column.
I want the row to be displayed at the bottom of the list.
I don't even need to compare the column values, need to just display the row as the last row based on the column value.
If SortComparer is only the way can you please provide me a sample code.
Hi,
I created a sample using the SortComparer like I mentioned, and I got it to work, but it was really very complicated.
So I found a simpler way to do this using the Move method on the rows collection.
So basically, the sample I attached here loops through all of the rows in the grid after it's bound and finds the row that I want to always be last. In this case, it's the row whose Type is "E".I just store a reference to that row in a variable.
Then I trap AfterSortChange and use the Move method to move that row to the bottom.
Thanks Mike.
The sample you gave works well on HeaderClickAction.
But I need my grid to be sorted when it is loaded.
I tried placing the Move in the formLoad after the for loop. If I do this, all my rows are not displaying in some cases.
Okay, so then you need to call the same method to Move the row after the grid is loaded and sorted the first time. You can probably do it in Form_Load, right after the loop that finds the row and stores it.
Yes MIke, As I told you in my last post, If I try to call the Move method in Form_Load after the loop, the grid is not displaying all the rows. It is displaying only the row with the cell value E.
This happens only when the first row has the cell value E.
Hm, that shouldn't be. So the rows are scrolled out of view? That probably happens because the grid is trying to maintain the same first visible row after the sort.
You should be able to correct it by using the grid.ActiveRowScrollRegion.Scroll methods to scroll to the top after you Move the row.
Thanks a lot Mike.
That helped.