Sorting DatagridviewTextbox Columns doesn't work

Answered
0
0

Hi,

Sorting columns in a datagridview doesn’t seem to work?

 

Attached a sample

  1. Run
  2. Try sorting the first column (which should work)
  3. Try sorting any onther column and notice the sorting doesn’t work

Is this a bug or am I doing something wrong?

 

Vincent

  • You must to post comments
Best Answer
0
0

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.

  • vincent_
    This fixed it thanks Luca!
  • You must to post comments
0
0

Hi Vincent,

this issue is fixed in Wisej.NET 3.1.10.

Best regards
Frank

  • You must to post comments
0
0

Hi Vincent,

this is fixed in our latest release (3.1.6)

Best regards
Frank

  • vincent_
    Awesome!
  • You must to post comments
0
0

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!

  • You must to post comments
1
0

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

 

  • You must to post comments
Showing 5 results
Your Answer

Please first to submit.