0

I have an datatable ( _dataTableAvailable) that has the folowing values:

Name        Id   Selected
- Global    2100  False
ASpecial    1200  False
BSpecial    2300  False
GSpecial    400   False

After I used the folowwing code:

DataView dataViewAvailable = new DataView(_dataTableAvailable, "selected=False", "name", DataViewRowState.CurrentRows);

The sort order is changed!!

Name        Id   Selected
ASpecial    1200  False
BSpecial    2300  False
- Global    2100  False
GSpecial    400   False

What I want is that I get the same order. How can I do this?

I use visual studio 2005 (C# 2.0).

Remco
  • 269
  • 3
  • 7
  • 16

2 Answers2

1

As it seems your datatable is ordered by Id ,So you may sort the dataview by Id and have the same results ! for code example take a look at the following link : DataView.Sort - more than just asc/desc (need custom sort)

Community
  • 1
  • 1
gwt
  • 2,331
  • 4
  • 37
  • 59
  • That the id's where in this order is just a coincedence. It could also had been: Name Id Selected - Global 2100 False ASpecial 200 False BSpecial 300 False GSpecial 400 False – Remco Jun 11 '12 at 09:07
  • I justed checked, the _dataTableAvailable is also sorted by "name". – Remco Jun 11 '12 at 09:15
  • So ! sort your dataview by name ! – gwt Jun 11 '12 at 10:12
0

I found it. This is a bug and the only solution is to add an extra column and call this something like "NameSort". In here put the folowwing order. So you get:

Name        Id   Selected NameSort
- Global    2100  False   0
ASpecial    1200  False   1
BSpecial    2300  False   2
GSpecial    400   False   3

Change the code to and it works fine:

DataView dataViewAvailable = new DataView(_dataTableAvailable, "selected=False", "NameSort", DataViewRowState.CurrentRows);
Remco
  • 269
  • 3
  • 7
  • 16