PC Review


Reply
Thread Tools Rate Thread

Delete row in datagrid - repost

 
 
Graeme Richardson
Guest
Posts: n/a
 
      8th Aug 2003
Hi, I have the VB code from
http://www.syncfusion.com/FAQ/WinFor...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


 
Reply With Quote
 
 
 
 
ClayB [Syncfusion]
Guest
Posts: n/a
 
      9th Aug 2003
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

"Graeme Richardson" <graeme@adeptx_nospam.co.nz> wrote in message
news:bh11ov$eov$(E-Mail Removed)...
> Hi, I have the VB code from
> http://www.syncfusion.com/FAQ/WinFor...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
>
>



 
Reply With Quote
 
Marc
Guest
Posts: n/a
 
      9th Sep 2003
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.

"Alfred" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> Hi,
>
> The code works well on a DataGrid that has no table style, but I couldn't
> get it to work properly on a grid that has a table style in it. Any
> workaround?
>
> Steps to reproduce the behavior:
> 1) Create to grids pointing to the same data source
> 2) Leave one of the grids without a table style
> 3) Put a table style on the other and add column styles as you wish
> 4) Select rows on both and delete them to compare their behavior
> 5) On the grid that has the table style, select a row clicking on its row
> header *once* and hit the delete key. It doesn't fire the DataGrid's
> PreProcessMessage method. However if you click on it's row header twice, it
> will.
>
> Some people said to override ProcessDialogKey but in my tests, it didn't
> work well neither.
>
> Thanks in advance.
>
> Alfred Gary Myers Jr.
>
> PS.: Thanks you guys at Syncfusion. Your FAQ help me a lot some months ago
> when I started working with .NET. Keep on with the good work!

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
REPOST - DataGrid AutoScroll rawCoder Microsoft Dot NET 0 20th Apr 2005 08:30 PM
REPOST - DataGrid AutoScroll rawCoder Microsoft VB .NET 0 20th Apr 2005 08:30 PM
REPOST - DataGrid AutoScroll rawCoder Microsoft C# .NET 0 20th Apr 2005 08:30 PM
Help with Advanced Datagrid (repost) Brad Shook Microsoft VB .NET 2 19th Oct 2004 02:21 PM
Repost: DataGrid with no rows kgs Microsoft ASP .NET 0 18th Nov 2003 03:37 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:06 PM.