datagrid master-details, itemchanged event

G

Guest

I'm struggling with the lack of useful events provided by DataGrid and CurrencyManager. (Windows Forms, not Web Forms
Right now the problem I'm having is this

I have two DataGrids in a master-detail configuration. Edits to certain cells need to immediately (or at least upon changing focus to another row) update items displayed on a map. I would like to minimize refreshing the map because it may become a flicker and/or throughput issue with large numbers of items, i.e. I'd rather update the map only when relevant data has been edited, as opposed to updating any time DataGrid cell or row focus changes

The only way I can seem to catch a CurrencyManager ItemChanged event is if I hit enter in a cell after editing it. If I edit a cell and then leave by any other method (tab, arrow, click other cell, leave datagrid altogether, etc.), the data is updated but the ItemChanged event never fires. Furthermore, a majority of the detail data contains only one row for each master row, which means the enter key does nothing since there is no next row for it to move to! In this case only ctrl-enter will suffice. I'm also finding that the DataTable RowChanging and RowChanged events are equally unpredictable in this situation, again depending on how I exited the cell/row being edited in the DataGrid. The CurrentCellChanged event is useless because you've already left the previous cell before you can determine if its value changed. Perhaps in CurrentCellChanged I could store the cell coordinates to be used as a "previous" cell the next time the event fires, but that seems a little shaky. The only other workaround I can think of would involve intercepting every possible means of moving from one cell to another (all tab, arrow, enter, etc. keypresses, mouse clicks, etc.) to determine if a cell's value changed before losing focus. This also is obviously an ugly, shaky solution
Any suggestions

On a related note, I've already had to force an EndEdit on the current cell when the details DataGrid loses focus -- I found that if you edit a detail cell and then click on a master row without first hitting enter on the detail cell, the wrong master row gets updated with the new data! The master row you just clicked on to leave the detail DataGrid gets the data, rather than the master row you had previously selected allowing you to edit its details. I've stripped this down to just the bare essentials and I'm convinced it's an internal .NET bug.
 
G

Guest

Sweet Mother of God, why did I ignore the DataTable ColumnChanged event for so long? It's exactly what I need. Should've known that when I finally gave up and posted I'd then figure it out five minutes later... In the back of my mind I thought ColumnChanging was one of those useless events that tells you something like "hey, the font size of the Sanskrit version of this column style has changed."
 
R

Ric Bernat

Well, I'm glad to find that somebody else is having basically the same
problem I'm having.

I was also searching for a way to save data on row change, as was getting
pretty frustrated. I tried events on the BindingManagerBase, then on the
DataSet, then on the DataTable. I'll DataTable.ColumnChanged now.
 

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