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.
The SortComparer property on the grid column takes an IComparer. So what you would do is create a class that implements IComparer and handle the Compare method.
This method will get called when the grid sorts the column and it will pass you two UltraGridCell objects.
To force a particular column to always show at the bottom of the grid is a bit tricky. The simplest thing to do would be to always return that the particular value in the row you want is always higher than every other value in every other row.
But this will only work when you sort ascending. So your IComparer class will have to know which direction the grid is sorting and reverse the return value when it' sorting descending.
Can you provide some more details on why you want this row to always be at the bottom? Is this row displaying some sort of summary information? If so, then maybe you should consider using the grid's built-in summaries instead of a row of data. Summaries always display at the bottom of the list by default.
This is not related to the Summary Information.
My scenario is something like this.
I have a grid with Date and Type Column.
I have three types of column values like "E, R and T".
I need to show the earliest date on top and then R on top of T and E always as the bottom row. My grid should look something like this. The type E should always display as the bottom row irrespective of its date value.
Date Type
03/07 R
03/07 T
03/08 R
03/08 T
03/07 E
What is the best way to solve this ?? Grouping ??
As I am new to Infragistics..I have never worked on grouping before... Can you please provide the sample code??
Thanks in Advance..
So you want the E row to always appear at the bottom, regardless of the date, and the regardless of whether the sort is ascending or descending? Is that right?
As I said above, the easiest way to do this would be to Fix row E at the bottom. But if you don't want that, then you would have to use the SortComparer like I suggested. I don't think grouping will help you there.
Basically, you would use a SortComparer for the Date column which also examines the Type column's value. If you are having trouble getting that to work, let me know and I will try to whip up a simple sample project for you.
Thanks a lot Mike.
That helped.
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.
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.
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.
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.