Cancelling Mousedown Event in Datagrid

G

GregM

I have a read only datagrid that is designed to coordinate itself with
textboxes. When the user clicks on a row in the datagrid, detailed
data for that row is displayed for editing in the textboxes. The
datagrid and textboxes are populated from the same underlying SQL
Server table but using different strongly typed data adapters and
datasets for display and editing. So I coordinate syncronization of
the two sets of data using code. I use the datagrid mousedown event
with hitTest to capture what row is clicked in the datagrid and then
find that row in the details dataset. This all works just fine.
However, before I allow the user to switch rows, I validate and save
the detailed information in the textboxes. My problem is that when the
detail in the textboxes fail my validation tests I want the data grid
to remain positioned on the invalid row until the details pass
validation and are saved. As it is now, the datagrid moves to the row
that was clicked and will not stay on the invalid row. In the meantime
my detail textboxes stay positioned on the invalid row until all data
passes validation. So, the datagrid selected row is now out of sync
with the details being displayed in the textboxes. I have tried to
reposition the datagrid using CurrentCellChanged event, the mouseUp
event, DataGrid.Unselect, DataGrid.IsSelected, and even in the
mousedown event after I issue the save/validate. It seems no matter
what event I use to try to cancel/revert the navigation in the
datagrid, the application wants to finish the mouse down action and
move the datagrid to the row that was clicked on. Then it seems there
are no other events firing that allow me to reposition the datagrid
row back to the original invalid row so that the datagrid and detail
texboxes stay in sync. Can anybody suggest an event for me to key in
on.
 
M

Morten Wennevik

Hi Greg,

I suspect you need to Inherit a DataGrid and override its
PreProcessMessage.
I can't tell you exactly how but I see it used quite frequently to filter
events.
 

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