I have a grid whose datasource is set to a list of objects. In the InitializeRow event, I am checking the value of each initialized row's object, and if that condition is true, then I am setting the hidden property on 3 cells to be true. When I try to sort or filter those columns with the hidden cells, they sort/filter as if the values were still there. Is there a way to treath these cells as if they contain nothing when sorting/filtering?
Try searching this forum for SortComparer and/or IComparer.
It's really pretty simple. The interface has only one method, Compare. It passes you two objects, which in this case will be UltraGridCells. You return a value indicator whether the first one is less than (-1), equal to (0), or greater than (1) the first one.
So in this case, you will cast each one into an UltraGridCell and then check the HiddenResolved property of each cell and from there, decide what to return.
Thank you. I think I'm going to try option 1. Do you know where I can find an example of how to make a SortComparer, so that I have a base that I can work off of?
Hi,
There are a couple of ways you could acheive this.
1) You could write your own SortComparer for the column which takes the Hidden state of the cell into account. That would take care of sorting. For filtering, you would also have to handle the FilterRow event and evaluate the row against the filter, once again taking the hidden state of the cell into account.
2) Another approach, which is a little more work, but probably more reliable in the long run would be to hide the actual column of data and create an unbound column to display to the user. You would use the InitializeRow event to copy the value from the "real" column into the unbound column and in the case where the cell is hidden, you could write a null into the unbound cell. This way, when the user sorts or filters the unbound column, the grid handles everything for you since the value of the cell they are actually dealing with is null.