Sorting in datagrid

  • Thread starter Thread starter DKC
  • Start date Start date
D

DKC

Hi,

Using VB.NET.

I have a datagrid having a strongly typed array of objects as its data
source.
The data from the array of objects is displayed by means of a table style,
which is fine, but I cannot sort the data when I click on the column header.
I have set the tablestype.allowsorting = true, but this has no effect.

On the other hand, when I set the datasource to a data table, sorting works
on column header click.

What should I do to get the table sorting to wotk with the array of objects?

Thanks
DKC
 
I'm not sure exactly what the problem is, but the grid is getting some
indication not to sort even though it sounds like a Single table bind.
There will be no functional difference whatsoever between binding to the
only table in a one table dataset and a dataset (what I mean is that you
won't lose anything) so go ahead an make the change. You may also want to
consider binding to a dataview, you can do quite a bit with them too without
losing any functionality.

HTH,

Bill
www.devbuzz.com
www.knowdotnet.com
 
Hi Bill,

The datagrid sorts when I map it to a data table.
However, when I map the datagrid to an array of objects ( class[] ), I
cannot sort on column header click.

Regards,
DKC
 
I find using DataViews as a data source for DataGrids works better for me
when I want to sort the DataGrid.
 
Hi William,

My front-end screen calls an assembly that returns an array of structures.
I don't want to transfer the contents of the array into a
data-table/data-view, as it is an additional overhead that I would rather do
without.
Instead, I am using the array as the datasource to the datagrid. I have
mapped the table style for the datagrid to the class[], the datagrid gets
populated with the data. It works, except for the sort.
When I DO put the data in the array of structures into a datatable and I map
the tablestyle to the datatable name, the sorting works.

Why does it not work if I use the array of structures directly?

Regards,
DKC
 
My guess is that you may save a bit on memory by using arrays, but I see no
way to sort using an array as the data source (that is not to say there
isn't one).

To be able to sort, if I had my data in an array, then I would convert it
to a DataTable and then create a DataView from that table, but then you are
right back where you don't want to be.


DKC said:
Hi William,

My front-end screen calls an assembly that returns an array of structures.
I don't want to transfer the contents of the array into a
data-table/data-view, as it is an additional overhead that I would rather do
without.
Instead, I am using the array as the datasource to the datagrid. I have
mapped the table style for the datagrid to the class[], the datagrid gets
populated with the data. It works, except for the sort.
When I DO put the data in the array of structures into a datatable and I map
the tablestyle to the datatable name, the sorting works.

Why does it not work if I use the array of structures directly?

Regards,
DKC





William LaMartin said:
I find using DataViews as a data source for DataGrids works better for me
when I want to sort the DataGrid.
 
Back
Top