hi,
let's say we have the following columns:
account name (ex: Mega Design) << string
created on (ex: 15) << integer
description (ex: 15 days ago) << string
if we click on account name column header, the grid sorts the column asc/desc according to its datatype (in this case string).
if we click on (description) column header, it will will sort the column as a string (15 days ago).
now, i want to hide (created on) column and keep (account name, description)
and make clicking on description sorts the grid as an integer...as if we have clicked on (created on)).
is that possible?
Here is the relevant SortComparer from Mike's sample:
internal class MySortComparer : IComparer { int IComparer.Compare(object x, object y) { // x and y will be UltraGridCell. So cast them to the correct type. var xCell = (UltraGridCell)x; var yCell = (UltraGridCell)y; // Get the rows var xRow = xCell.Row; var yRow = yCell.Row; // Get the value of the "Int32 1" cell in each row. // If there is a chance that the value will be null or // DBNull, you will need to check for that here. int xInt = (int)xRow.Cells["Int32 1"].Value; int yInt = (int)yRow.Cells["Int32 1"].Value; // Return the comparison of the two integer values. return xInt.CompareTo(yInt); } }
And the logic from the InitializeLayout method where the class is instantiated:
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { var layout = e.Layout; var band = layout.Bands[0]; var ov = layout.Override; ov.HeaderClickAction = HeaderClickAction.SortMulti; band.Columns["String 1"].SortComparer = new MySortComparer(); }
Can you post the code here? I'm unable to open the file.
Hi Mr. saltzman,
that's EXACTLY what i wanted, it works like a charm.
thanks a lot.
Hi,
Yes, this is actually pretty easy. There is a SortComparer property on the UltraGridColumn. So this allows you to customize the sorting of any column however you want. In this case, it's even easier, because you aren't doing any complex sorting, you just want to re-direct the sorting of one column to use the values from another column.
I have attached a small sample project that sorts a string column ("String 1") by the value of an integer column ("Int32 1").