By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,458 Members | 1,250 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,458 IT Pros & Developers. It's quick & easy.

DataGrid / DataTable event problem

P: n/a
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
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.