No Respect from Datagrid

  • Thread starter Thread starter Haim Katz
  • Start date Start date
H

Haim Katz

I have a winform with a datagrid bound to a dataview with the allowDelete
property set to false.
The datagrid is readonly. When the user enters the datagrid and presses the
delete key the row is not deleted, but the currentrowindex is changed to -1.

When the grid looses focus I get an error "Error when committing the row to
the original data store, row index is negative...". I've tried to trap this
error in the datagrid's validating, keydown, lostfocus events with the
following code:

IF datagrid1.currentrowindexs<0 then datagrid1.currentrowindex = 0

The event is fired and the code is run, but the datagrid ignores my
instructions and the index remains at -1.

Ive tried using a derived grid overiding the PreprocessMessage function
with
.....
if msg.msg = wm_keydown and keycode = keys.delete then
return true
End if

This also fires but does not prevent the error.

Can anyone help me get my respect back and have the datagrid do what I want?

Haim
 
Hello Haim,

You can intercept the Delete keystroke but you will need to do it in the
ProcessCmdKey override.
 
Thanks Dmitriy. I give it a try.

Haim
Dmitriy Lapshin said:
Hello Haim,

You can intercept the Delete keystroke but you will need to do it in the
ProcessCmdKey override.

--
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

Haim Katz said:
I have a winform with a datagrid bound to a dataview with the allowDelete
property set to false.
The datagrid is readonly. When the user enters the datagrid and presses the
delete key the row is not deleted, but the currentrowindex is changed to -1.

When the grid looses focus I get an error "Error when committing the row to
the original data store, row index is negative...". I've tried to trap this
error in the datagrid's validating, keydown, lostfocus events with the
following code:

IF datagrid1.currentrowindexs<0 then datagrid1.currentrowindex = 0

The event is fired and the code is run, but the datagrid ignores my
instructions and the index remains at -1.

Ive tried using a derived grid overiding the PreprocessMessage function
with
....
if msg.msg = wm_keydown and keycode = keys.delete then
return true
End if

This also fires but does not prevent the error.

Can anyone help me get my respect back and have the datagrid do what I want?

Haim
 
Back
Top