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

Xceed Support
Member
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:

e.g.,
<code>
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();
}
row.EndEdit();
}
}

private void button1_Click( object sender, EventArgs e )
{
gridControl1.Columns[ 0 ].DataComparer = new AddressComparer();
}
</code>

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