On Sort Event

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there an event that is invoked when a user sorts a
column in a Windows Forms DataGrid?

I have context senstive icons that are enabled\disabled
depending upon the selected item in the datagrid. When I
sort the datagrid the selected item changes. I can not
find the event that is fired when the sorting occurrs
therfore I cannot enable\disable the icons

Thanks in advance,
James
 
James,

There is no event to do this with the DataGrid. What you could do is
check the DataView that the grid is bound to at the time you show the
context menu, and then modify it before you show it based on that value. If
the processing is too intensive for that, then I would look at extending the
DataGrid class and handling the windows message for clicking on the
datagrid. If you get a button click, then check to see if it is on a
header, and then check the sort property before and after.

Hope this helps.
 
Nick,

I was already using the method you supplied for my
menus. However I also have a toolbar. I enable and
disable some features based on the selected item.

I just found something that appears to be working. The
dataview ListChanged event seems to fire when the sort
button is clicked.

I do have another question.

Is there a way to initialized the sorted column when a
datatable is bound to a dataset. for instance if I knew
the 2nd column was sorted last and I want to refresh the
datagrid from my database I can rebind the datagrid and
set the sort to the 2nd column. It currently gets reset
when I rebind.

James
-----Original Message-----
James,

There is no event to do this with the DataGrid. What you could do is
check the DataView that the grid is bound to at the time you show the
context menu, and then modify it before you show it based on that value. If
the processing is too intensive for that, then I would look at extending the
DataGrid class and handling the windows message for clicking on the
datagrid. If you get a button click, then check to see if it is on a
header, and then check the sort property before and after.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Is there an event that is invoked when a user sorts a
column in a Windows Forms DataGrid?

I have context senstive icons that are enabled\disabled
depending upon the selected item in the datagrid. When I
sort the datagrid the selected item changes. I can not
find the event that is fired when the sorting occurrs
therfore I cannot enable\disable the icons

Thanks in advance,
James


.
 
Never mind I found it DataView.Sort pretty clever how it
works.

-----Original Message-----
Nick,

I was already using the method you supplied for my
menus. However I also have a toolbar. I enable and
disable some features based on the selected item.

I just found something that appears to be working. The
dataview ListChanged event seems to fire when the sort
button is clicked.

I do have another question.

Is there a way to initialized the sorted column when a
datatable is bound to a dataset. for instance if I knew
the 2nd column was sorted last and I want to refresh the
datagrid from my database I can rebind the datagrid and
set the sort to the 2nd column. It currently gets reset
when I rebind.

James
-----Original Message-----
James,

There is no event to do this with the DataGrid. What you could do is
check the DataView that the grid is bound to at the
time
you show the
context menu, and then modify it before you show it based on that value. If
the processing is too intensive for that, then I would look at extending the
DataGrid class and handling the windows message for clicking on the
datagrid. If you get a button click, then check to see if it is on a
header, and then check the sort property before and after.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Is there an event that is invoked when a user sorts a
column in a Windows Forms DataGrid?

I have context senstive icons that are enabled\disabled
depending upon the selected item in the datagrid. When I
sort the datagrid the selected item changes. I can not
find the event that is fired when the sorting occurrs
therfore I cannot enable\disable the icons

Thanks in advance,
James


.
.
 
Back
Top