Hi,
Sorting columns in a datagridview doesn’t seem to work?
Attached a sample
Is this a bug or am I doing something wrong?
Vincent
Unfortunately it’s a regression related to sorting a DataGridView data bound to a source that doesn’t support sorting. It’s fixed in the current internal build and will be available shortly If you use dgv.Fill(dataSource) you can see the correct sorting.
Hi Vincent,
this issue is fixed in Wisej.NET 3.1.10.
Best regards
Frank
Hi Vincent,
this is fixed in our latest release (3.1.6)
Best regards
Frank
Surely the DataGridView should be able to handle sorting the basic types like strings and numbers automatically. Or I’m just spoiled in the past by using the DevExpress grid in WinForms. ?
I’ll give your suggestion a try, thanks for the reply!
Don’t know what could possibly go wrong here. You might consider an event handler to have more control over the sorting, e.g. to sort durations in der format hours:minutes, that’s c#:
dataGridView1.SortCompare += DataGridView1_SortCompare;
private void DataGridView1_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
{
if (e.Column.Name == Tags.Duration)
{
e.Handled = true;var v1 = e.CellValue1 as string;
var v2 = e.CellValue2 as string;var d1 = 0;
var d2 = 0;if (v1.Contains(‘:’))
{
var c1 = v1.Split(‘:’);
d1 = int.Parse(c1[0]) * 60 + int.Parse(c1[1]);
}if (v2.Contains(‘:’))
{
var c2 = v2.Split(‘:’);
d2= int.Parse(c2[0]) * 60 + int.Parse(c2[1]);
}e.SortResult = System.Collections.Comparer.DefaultInvariant.Compare(d1, d2);
}
}
Cheers, Gerhard
Please login first to submit.