473,395 Members | 2,079 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

DataGrid Row Deletion


I posted before and got the reply below, which really
doesn't help me at all. I really didn't understand what
the responder was talking about

I'd like someone who is a microsoft expert to help me with
some specifics on this problem:

I have to do some specific data verification before saving
a row or group of rows to the database (the data
validation in the datagrid really doesn't help all that
much).

I need to find a way to detect whether a user deletes a
row on the datagrid so that I can delete it in the
database (without using the database as a direct
datasource).

What events (and some specific code would be helpful) can
I use to detect row deletions, even if you have some
around-about code.

Thanks again,

Mike

--------------------------------------------OLD REPLY
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.

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

"Mike" <st******@mail.ucf.edu> wrote in message
news:00****************************@phx.gbl...
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


Nov 20 '05 #1
1 1717
Mike,

The harsh reality is there are no .NET events you could employ to detect
this situation (the bound data source's RowDeleting event does not seem to
be useful). That's why I have suggested to switch to the Windows API level
and playing with the WM_KEYDOWN notification. I have posted this suggestion
as it has worked just fine for me - "and no one ever said that being heretic
is easy" (to quote the good old "Heretic" game by ID Software).

What I was actually wrong about was my suggestion to override the WndProc
method. I have just reviewed my code doing almost the same you are trying to
do and found out that overriding PreProcessMessage should be enough.

Here's a code snippet that might help. I am not 100% sure of the syntax - I
am a C# guy after all, but it should convey the main idea.

Public Class CustomDataGrid
Inherits DataGrid

Private Const WM_KEYDOWN As Integer = &H0100
Private Const WM_SYSKEYDOWN As Integer= &H0104

Public Overrides Function PreProcessMessage(ByRef msg As Message) As
Boolean

If msg.Msg = WM_KEYDOWN Then

Dim keyPressed As Keys = DirectCast(msg.WParam.ToInt32(), Keys) And
Keys.KeyCode

If keyPressed == Keys.Delete Then
' Raise a custom event here that would trigger the pre-delete
validation.
' The event should be cancellable and if the event handler has
cancelled the
' event, you should return True immediately to "eat" the keystroke
and prevent
' the base grid from handling the keystroke itself.
' If the deletion has been allowed by the validating code, you should
pass the
' keystroke to the base grid with the following statement:
' PreProcessMessage = MyBase.PreProcessMessage(msg)
End If
Else
PreProcessMessage = MyBase.PreProcessMessage(msg)
End If

End Function
End Class

P.S. Don't forget about the Alt-Del combo - this works exactly as Del in the
DataGrid but won't be caught by the code given. To intercept this keystroke,
you should override the ProcessCmdKey method of the DataGrid class and do a
similar thing. The only difference is that you should check for
WM_SYSKEYDOWN instead of WM_KEYDOWN and add the

"ModifierKeys = Keys.Alt" check to the "keyPressed == Keys.Delete"
condition.

P.P.S. Please feel free to ask specific questions on what is unclear in my
reply and I will be glad to elaborate.

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

"mike" <st******@mail.ucf.edu> wrote in message
news:02****************************@phx.gbl...

I posted before and got the reply below, which really
doesn't help me at all. I really didn't understand what
the responder was talking about

I'd like someone who is a microsoft expert to help me with
some specifics on this problem:

I have to do some specific data verification before saving
a row or group of rows to the database (the data
validation in the datagrid really doesn't help all that
much).

I need to find a way to detect whether a user deletes a
row on the datagrid so that I can delete it in the
database (without using the database as a direct
datasource).

What events (and some specific code would be helpful) can
I use to detect row deletions, even if you have some
around-about code.

Thanks again,

Mike

--------------------------------------------OLD REPLY
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.

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

"Mike" <st******@mail.ucf.edu> wrote in message
news:00****************************@phx.gbl...
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


Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Chumley the Walrus | last post by:
IN my code behind .vb page for a delete records script (this also does a deletion confirmation with a javascript popup, this gets called on my front .aspx page with the datagrid), I'm not sure if...
9
by: Pam Ammond | last post by:
After clicking btnDeleteSize_Click in frmSize, I move to frmSizeDelete, allow deleting a Size using a datagrid, and then return to frmSize and want to update the datagrid in frmSize to reflect the...
4
by: Rod | last post by:
I posted a message to this group yesterday asking how to pass parameters to a web form that is the source of an IFrame on a parent web form. I've gotten my answer, and it works. Thanks! Now I...
6
by: JenHu | last post by:
Hi experts, I want to add a delete button in my datagrid, and before it deletes from database, I want to have a confirm dialog box for this deletion. I am entry level to the vb.net, and don't...
1
by: Dan | last post by:
Hi all, I have a question about datagrid: let's say I have a datagrid which shows the categories for some items; each category has an ID field and a description. I use an ASP.NET page with a...
0
by: Mike Bravo | last post by:
When I delete a row from my dataset, using 'Delete the current row Dim ll_cur_row As Long ll_cur_row = Dg_base1.CurrentRowIndex() If ll_cur_row >= 0 Then
0
by: excelleinc.com | last post by:
Hello, I know that this question was here quite a few times but I was wondering if anyone atually found a solution/work around for it. I'm trying to prevent users from deleting certain rows in...
0
by: Calvin KD | last post by:
Hi everyone, I'd like to enable users to select/mark multiple rows (records) in my datagrid for deletion. I have provided a checkbox column with a checkbox in the header for "Select All" option....
4
by: mamun | last post by:
Hi All, I have the following situation and am looking for answer in C#. I have a datagrid and putting checkbox next to each record. In the header I have a Delete button. I want users to...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.