Delete row in datagrid - repost

  • Thread starter Graeme Richardson
  • Start date
G

Graeme Richardson

Hi, I have the VB code from
http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q889q.
How do I implement it?

I want the function PreProcessMessage to fire (code below) when I select a
record and type the delete key.
I have a DataGrid called grdTown that is populated with data from a
DataTable called mdtTown [also a DataAdapter (madpTown) and
BindingBaseManager (mbmbTown)].

Cheers, Graeme.

Public Class SubClass_DataGrid
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
 
C

ClayB [Syncfusion]

Instead of having a DataGrid called grdTown, you need to have a
SubClass_DataGrid called grdTown. Then the PreProcessMessage will be hit as
your press a key while the grid has focus.

One way you could do this is to go through the code where grdTown is
declared and created (normally two lines), and change
System.Windows.Forms.DataGrid to SubClass_DataGrid . Another way is to build
a class library holding this code and then import the library to your
ToolBox and this should allow you to drag and drop a SubClass_DataGrid
object.

=======================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools
 
M

Marc

I've experienced the exact same problem since upgrading to Framework
1.1. In the previous framework the PreProcessMessage handler would get
called every time you type Delete when you've selected a row. Now, for
some reason, it only works sometimes.

Has anyone solved this issue? Its very frustrating. Delete confirm is
really something that is usually going to be required in any
application - it would have been desirable to have this implemented as
part of the standard DataGrid control in the first place.
 

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