DataGrid sort

G

Guest

I need to sort a DataGrid on a specified column without requiring the user to click a column header. How do I do this programmatically?
Normally I would set the DataGrid DataSource to default or custom DataView and set the sort property, but in this case the DataSource is a ChildRelation.

Read on if you need more explanation.

I have two DataGrids on this particular Windows Form.
The first has DataSource set to a DataView on a table in my DataSet which is a parent in a relation. This allows the parent grid to display filtered and sorted data.
The second DataGrid DataSource is the same DataView with DataMember set to a ChildRelation. This allows a user to move through rows on the parent table grid and see the related rows on the child table grid.

The problem is that I can set a filter and sort on the parent table DataSource but not on the child table. A sort is required on the child table, and I can't expect the user to click on a column header to do it.

Any ideas are alternate approaches? Thanks.
 
C

ClayB [Syncfusion]

Try this to see it it handles this case.

CurrencyManager cm = (CurrencyManager)
this.dataGrid1.BindingContext[dataGrid1.Datasource, dataGrid1.DataMember];
DataView dv = (DataView) cm.List;
dv.Sort = "SomeColumn";

========================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools

Harlan Marshall said:
I need to sort a DataGrid on a specified column without requiring the user
to click a column header. How do I do this programmatically?
Normally I would set the DataGrid DataSource to default or custom DataView
and set the sort property, but in this case the DataSource is a
ChildRelation.
Read on if you need more explanation.

I have two DataGrids on this particular Windows Form.
The first has DataSource set to a DataView on a table in my DataSet which
is a parent in a relation. This allows the parent grid to display filtered
and sorted data.
The second DataGrid DataSource is the same DataView with DataMember set to
a ChildRelation. This allows a user to move through rows on the parent table
grid and see the related rows on the child table grid.
The problem is that I can set a filter and sort on the parent table
DataSource but not on the child table. A sort is required on the child
table, and I can't expect the user to click on a column header to do it.
 
G

Guest

I had high hopes for this solution, but the child table DataGrid remains unsorted.

I'm guessing that this is because you're creating an additional DataView which has it's table set to the same source as the DataGrid's, but because the DataGrid is not bound to that DataView it does not use it's sort property. The child table DataGrid apparently must be bound to the ChildRelation to show related rows as the user moves through rows in the parent table DataGrid. I tried binding the child DataGrid to this new DataView, but the relation to the parent is broken.

I was trying to figure out a way to programatically fire the same event that occurs when a user clicks the column header.

Thanks for the effort. I wish it had worked. Any other ideas?
--
Harlan Marshall
Database/GIS Administrator
Utility Services of Alaska
Fairbanks, AK


ClayB said:
Try this to see it it handles this case.

CurrencyManager cm = (CurrencyManager)
this.dataGrid1.BindingContext[dataGrid1.Datasource, dataGrid1.DataMember];
DataView dv = (DataView) cm.List;
dv.Sort = "SomeColumn";

========================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools

Harlan Marshall said:
I need to sort a DataGrid on a specified column without requiring the user
to click a column header. How do I do this programmatically?
Normally I would set the DataGrid DataSource to default or custom DataView
and set the sort property, but in this case the DataSource is a
ChildRelation.
Read on if you need more explanation.

I have two DataGrids on this particular Windows Form.
The first has DataSource set to a DataView on a table in my DataSet which
is a parent in a relation. This allows the parent grid to display filtered
and sorted data.
The second DataGrid DataSource is the same DataView with DataMember set to
a ChildRelation. This allows a user to move through rows on the parent table
grid and see the related rows on the child table grid.
The problem is that I can set a filter and sort on the parent table
DataSource but not on the child table. A sort is required on the child
table, and I can't expect the user to click on a column header to do it.
Any ideas are alternate approaches? Thanks.

--
Harlan Marshall
Database/GIS Administrator
Utility Services of Alaska
Fairbanks, AK
 
C

ClayB [Syncfusion]

This code seems to work in the attached sample (if I understand how your
grids were bound). Now when you change rows in your parent grid, this will
change out the child grid contents and any existing child sort will be lost.
But you could re-apply the sort at this point.

===========================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools


Harlan Marshall said:
I had high hopes for this solution, but the child table DataGrid remains unsorted.

I'm guessing that this is because you're creating an additional DataView
which has it's table set to the same source as the DataGrid's, but because
the DataGrid is not bound to that DataView it does not use it's sort
property. The child table DataGrid apparently must be bound to the
ChildRelation to show related rows as the user moves through rows in the
parent table DataGrid. I tried binding the child DataGrid to this new
DataView, but the relation to the parent is broken.
I was trying to figure out a way to programatically fire the same event
that occurs when a user clicks the column header.
Thanks for the effort. I wish it had worked. Any other ideas?
--
Harlan Marshall
Database/GIS Administrator
Utility Services of Alaska
Fairbanks, AK


ClayB said:
Try this to see it it handles this case.

CurrencyManager cm = (CurrencyManager)
this.dataGrid1.BindingContext[dataGrid1.Datasource, dataGrid1.DataMember];
DataView dv = (DataView) cm.List;
dv.Sort = "SomeColumn";

========================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools

Harlan Marshall said:
I need to sort a DataGrid on a specified column without requiring the
user
to click a column header. How do I do this programmatically?
Normally I would set the DataGrid DataSource to default or custom
DataView
and set the sort property, but in this case the DataSource is a
ChildRelation.
Read on if you need more explanation.

I have two DataGrids on this particular Windows Form.
The first has DataSource set to a DataView on a table in my DataSet
which
is a parent in a relation. This allows the parent grid to display filtered
and sorted data.
The second DataGrid DataSource is the same DataView with DataMember
set to
a ChildRelation. This allows a user to move through rows on the parent table
grid and see the related rows on the child table grid.
The problem is that I can set a filter and sort on the parent table
DataSource but not on the child table. A sort is required on the child
table, and I can't expect the user to click on a column header to do it.
Any ideas are alternate approaches? Thanks.

--
Harlan Marshall
Database/GIS Administrator
Utility Services of Alaska
Fairbanks, AK
 
G

Guest

I can find no attached sample code with your post. If you could email it to me as an attachment maybe that would work. (e-mail address removed)

Thanks. I feel bad that you are making an effort to help me and I'm not able to see what it is. I appreciate it greatly!

--
Harlan Marshall
Database/GIS Administrator
Utility Services of Alaska
Fairbanks, AK


ClayB said:
This code seems to work in the attached sample (if I understand how your
grids were bound). Now when you change rows in your parent grid, this will
change out the child grid contents and any existing child sort will be lost.
But you could re-apply the sort at this point.

===========================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools


Harlan Marshall said:
I had high hopes for this solution, but the child table DataGrid remains unsorted.

I'm guessing that this is because you're creating an additional DataView
which has it's table set to the same source as the DataGrid's, but because
the DataGrid is not bound to that DataView it does not use it's sort
property. The child table DataGrid apparently must be bound to the
ChildRelation to show related rows as the user moves through rows in the
parent table DataGrid. I tried binding the child DataGrid to this new
DataView, but the relation to the parent is broken.
I was trying to figure out a way to programatically fire the same event
that occurs when a user clicks the column header.
Thanks for the effort. I wish it had worked. Any other ideas?
--
Harlan Marshall
Database/GIS Administrator
Utility Services of Alaska
Fairbanks, AK


ClayB said:
Try this to see it it handles this case.

CurrencyManager cm = (CurrencyManager)
this.dataGrid1.BindingContext[dataGrid1.Datasource, dataGrid1.DataMember];
DataView dv = (DataView) cm.List;
dv.Sort = "SomeColumn";

========================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools

I need to sort a DataGrid on a specified column without requiring the user
to click a column header. How do I do this programmatically?
Normally I would set the DataGrid DataSource to default or custom DataView
and set the sort property, but in this case the DataSource is a
ChildRelation.

Read on if you need more explanation.

I have two DataGrids on this particular Windows Form.
The first has DataSource set to a DataView on a table in my DataSet which
is a parent in a relation. This allows the parent grid to display filtered
and sorted data.
The second DataGrid DataSource is the same DataView with DataMember set to
a ChildRelation. This allows a user to move through rows on the parent table
grid and see the related rows on the child table grid.

The problem is that I can set a filter and sort on the parent table
DataSource but not on the child table. A sort is required on the child
table, and I can't expect the user to click on a column header to do it.

Any ideas are alternate approaches? Thanks.

--
Harlan Marshall
Database/GIS Administrator
Utility Services of Alaska
Fairbanks, AK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top