S
Suzanne
I'd like to know how can I put up a confirmation question when the
user tries to delete a row in the datagrid by clicking on the row
header and pressing the Delete key?
I have found this code on a windows forms FAQ site :
Public Class DataGrid_Custom
Inherits DataGrid
Private Const WM_KEYDOWN = &H100
Public Overrides Function PreProcessMessage(ByRef msg As
System.Windows.Forms.Message) As Boolean
Dim keyCode As Keys = CType((msg.WParam.ToInt32 And
Keys.KeyCode), Keys)
If msg.Msg = WM_KEYDOWN And keyCode = Keys.Delete Then
If MessageBox.Show("Delete This Row?", "Confirm
Delete", MessageBoxButtons.YesNo) = DialogResult.No Then
Return True
End If
End If
Return MyBase.PreProcessMessage(msg)
End Function
End Class
but it does not work consistently - ie when I first click into the
rowheadercell of the row I want to delete, the row imediatley goes in
to edit mode (with the pencil icon) and the row deletes without the
message. If I click out of the row and then go back in ie when the
arrow icon shows in the row header cell the code works properly and I
get the confirmation question.
Is there someway that I can make the datagrid only go into edit mode
when I click into a textbox within in it and not when I click on the
header cells?
I want to be able to do this using key up/down/press events of the
datagrid and not use e.Action.Delete in
System.Data.DataRowChangeEventArgs of the datatable as I don't want
to call acceptchanges on my datatable (since this will create problems
further for me further down the line)
Any ideas would be gratefully recieved
Thanks
Suzanne
user tries to delete a row in the datagrid by clicking on the row
header and pressing the Delete key?
I have found this code on a windows forms FAQ site :
Public Class DataGrid_Custom
Inherits DataGrid
Private Const WM_KEYDOWN = &H100
Public Overrides Function PreProcessMessage(ByRef msg As
System.Windows.Forms.Message) As Boolean
Dim keyCode As Keys = CType((msg.WParam.ToInt32 And
Keys.KeyCode), Keys)
If msg.Msg = WM_KEYDOWN And keyCode = Keys.Delete Then
If MessageBox.Show("Delete This Row?", "Confirm
Delete", MessageBoxButtons.YesNo) = DialogResult.No Then
Return True
End If
End If
Return MyBase.PreProcessMessage(msg)
End Function
End Class
but it does not work consistently - ie when I first click into the
rowheadercell of the row I want to delete, the row imediatley goes in
to edit mode (with the pencil icon) and the row deletes without the
message. If I click out of the row and then go back in ie when the
arrow icon shows in the row header cell the code works properly and I
get the confirmation question.
Is there someway that I can make the datagrid only go into edit mode
when I click into a textbox within in it and not when I click on the
header cells?
I want to be able to do this using key up/down/press events of the
datagrid and not use e.Action.Delete in
System.Data.DataRowChangeEventArgs of the datatable as I don't want
to call acceptchanges on my datatable (since this will create problems
further for me further down the line)
Any ideas would be gratefully recieved
Thanks
Suzanne