0

How to get a list of items, that is in sorted gridControl?

I need to create a new List with only values, sorted by GridControl.

Artem Makarov
  • 874
  • 3
  • 14
  • 25

1 Answers1

3

probably not the most elegant solution but as found on the devexpress site because i hit the same problem a while a go:

the main gridview of the gridcontrol has a property DataRowCount, so you could do this;

List<DataRow> dataRows = new List<DataRow>();
for (int i = 0; i < gridView1.DataRowCount; i++) {
    DataRow row = gridView1.GetDataRow(i);
    dataRows.Add(row);
}

and then you can do whatever, or select a value from the row before you add it to an collection while using the column header:

object result = gridview1.GetDataRow(i)["ID"];
wterbeek
  • 451
  • 9
  • 26
  • Thank you! But I can't get "DataRowCount", VisualStudio can't find this property... And GridControl don't have "MainView" property... Is that works only for version 12 of assemblies? – Artem Makarov Jul 25 '12 at 12:26
  • no, it worked since i started to use the devexpress controls which would be from version 11 onward, so i assume it should work there as well. in my experience though, devExpress sometimes changes the names of their properties from some reason. also the knowledgebase of devexpress is a huge help to me; have a look at it [here](http://documentation.devexpress.com/#HomePage/CustomDocument9453) – wterbeek Jul 25 '12 at 12:54
  • Yes! It works! but it works this way: for (int i = 0; i < dataTable.VisibleRowCount; i++) { var row = dataTable.GetRow(i); – Artem Makarov Jul 25 '12 at 13:05
  • i see what happend, code i posted is from the winform's library it might be different for the wpf libraries, glad i could help :) – wterbeek Jul 25 '12 at 13:11