469,572 Members | 1,571 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,572 developers. It's quick & easy.

DataGrid / DataTable event problem

The following assumes a System.Windows.Forms.DataGrid with a System.Data.DataTable set as the DataSource. I'm programming in C#

Here's my scenario

I click in a cell on a DataGrid. I enter some text. Before changing to another cell in the DataGrid, I move my mouse pointer off the DataGrid and change the selected item in a ListBox or TreeView.

Here's my question

Which should fire first, the DataTable's RowChanged/CellChanged event or the event indicating the selected node/item has changed in the TreeView/ListBox control

Here's what is happening

If I change the selected item in the Listbox, the DataTable's RowChanged/CellChanged events fire BEFORE the ListBox's SelectedValueChanged event

If I change the selected node in the TreeView, the DataTable's RowChanged/CellChanged events fire AFTER the TreeView's AfterSelected event

For starters, these event orderings seem inconsistent with each other

Here's my problem

My TreeView is controlling what is displayed in my DataGrid (and what populates the underlying DataTable). When I enter something in a DataGrid cell, then change the selected node in my TreeView without first changing the cell in my DataGrid to force an update, I don't get to handle the RowChanged/CellChanged event until AFTER I've updated the DataSource for the DataGrid to a different DataTable that corresponds the newly selected tree node. I've got an old DataTable throwing the event that no longer matches the context I'm in, which is defined by the node selected in the TreeView

In Summary

Users have to change to a different cell every time they make a change in the DataGrid or they lose their change if they change what's loaded into the DataGrid by selecting a different node in the tree. (Or even if they save--I'm presented with a related problem when they click on a toolbar button or menu item to save the changes they've made to the data in the grid--they lose what's in the current cell

Is there a straightforward way around this problem? I've tried programatically changing the cell in the DataGrid to force an update as a hack to get by this, but had no success with that. Can anyone tell me how this was designed to be used, or a good way around this problem

Thanks in advance for any help!
Nov 16 '05 #1
0 2878

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Emerson | last post: by
7 posts views Thread by localhost | last post: by
reply views Thread by Steve | last post: by
4 posts views Thread by The Alchemist | last post: by
2 posts views Thread by Ben | last post: by
4 posts views Thread by KB | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.