Datagrid Row Delete Detection

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

Hi,

I am working with the data in the datagrid behind the
scenes because I have very specific data validation that
needs to be done before saving to the database.

I am wondering, what event detects when the user
highlights a row and then hits "Delete" button. I have
tried the keypress event, but that doesn't work.

Thank you,

Mike
 
Hi Mike,

I'm afraid you'll have to inherit from the DataGrid and override its WndProc
to handle the Del key upon WM_KEYDOWN notifications. You can also try
overriding ProcessDialogKey not to deal with raw Win32 API messages but I am
not sure this will help.
 
Hey,

If your Datagrid is bound to a dataset, you can use the Dataset's
Row/Column changing events to do the validation code:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemdatadatatableclassrowdeletingtopic.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/
vbtskvalidatingdataduringrowchanges.asp

You can add your validation code to the DataTable.RowDeleting event, and
make sure you delete the right row.

Hope it helps.

Aiwen
VB.Net Team
 
Aiwen,

I remember there were issues with that way of validation related to
cancelling an action when it was not valid. Something like the RowDeleting
event had been cancelled but the corresponding row disappeared from the grid
anyway (but remained intact in the DataTable).

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE
 
Back
Top