472,354 Members | 1,711 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,354 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 1627
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
1
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
0
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...

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.