Change sorting type in Infragistics column

667 Views Asked by At

I have a problem with sorting in Infragistics column.

I have a column with numbers (long type), but the column data type is a string.

So now it sorts by a string which is not valid. If I change column data type to typeof(long), the sorting stopped working.

Do you know how can I change sorting type for numeric values?

Updated:

myCell.Column.DataType = typeof(string);

I'm using Infragistics4.Win.v12.2

1

There are 1 best solutions below

0
On BEST ANSWER

You can't change the DataType property of the Column if it is a column bounded to a DataSource. Instead you can create a new column in the datasource with an expression initializer that allows you to convert the String column in a long column. Then in the grid you can hide the string column and let your user see only the column created with an expression.

Suppose you have a DataTable loaded in this way

DataTable dt = new DataTable();
sqlAdapter.Fill(dt);

Now you can add a new column of long type using an Expression that copies the content of the String column (I assume that every single row is convertible to long)

dt.Columns.Add("NewLongCol", typeof(long), "StringCol");
yourGrid.DataSource = dt;

Finally in the InitializeLayout event handler of the grid hide the string column and position the long column in its place

private void yourGrid_InitializeLayout(object sender, InitializeLayoutEventArgs e)
{
    UltraGridBand b = e.Layout.Bands[0];
    int pos = b.Columns["StringCol"].Header.VisiblePosition;
    b.Columns["StringCol"].Hidden = true;
    b.Columns["NewLongCol"].Header.VisiblePosition = pos;
}