Home Forums WinForms controls Xceed Grid for WinForms Sorting on string column as integer

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • User (Old forums)
    Post count: 23064
    #15718 |

    I have a column in the grid that is defined as type String. In some cases, all the values are known to be integers – I’d like to put a checkbox on my form saying “Treat Column A as Numbers” and have the grid sort on this column, treating the values as numbers, instead of as string values – how do I do an override to get the Grid to treat the column as integers, instead of as strings?

    Imported from legacy forums. Posted by Shmuel (had 1886 views)

    Xceed Support
    Post count: 5658

    You will need to customize your DataComparer. To do so, there is an excellent topic on <a href=”http://doc.xceedsoft.com/products/Xceedgrid/Custom_Sorting.html”>Custom Sorting</a> in our documentation.

    With a GridControl dropped on the form, I was able to change the DataComparer at runtime:

    private void Form1_Load( object sender, EventArgs e )
    Column col1 = new Column( “Column1” );
    Column col2 = new Column( “Column2” );
    Column col3 = new Column( “Column3” );
    Column col4 = new Column( “Column4” );
    gridControl1.Columns.Add( col1 );
    gridControl1.Columns.Add( col2 );
    gridControl1.Columns.Add( col3 );
    gridControl1.Columns.Add( col4 );

    for( int i = 0; i < 20; i++ )
    Xceed.Grid.DataRow row = gridControl1.DataRows.AddNew();
    foreach( Cell cell in row.Cells )
    cell.Value = i.ToString();

    private void button1_Click( object sender, EventArgs e )
    gridControl1.Columns[ 0 ].DataComparer = new AddressComparer();

    Imported from legacy forums. Posted by CharlesB (had 3060 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.