473,473 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

datagrid - cancelling row deletion

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 datagrid. This
rows are specified in rownumber property. To do this I have implemented
custom datagrid that looks like this:

Class DGCustom

Inherits DataGrid

Private Const WM_KEYDOWN As Integer = &H100

Friend intRowNumber As Integer = 0

Friend Property rownumber() As Integer

Get

Return intRowNumber

End Get

Set(ByVal Value As Integer)

intRowNumber = Value

End Set

End Property

Public Overrides Function PreProcessMessage(ByRef msg As
System.Windows.Forms.Message) As Boolean

Dim keycode As Keys

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

Protected Overrides Function processdialogkey(ByVal keydata As
System.Windows.Forms.Keys) As Boolean

Dim pt As Point

Dim hti As DataGrid.HitTestInfo

pt = Me.PointToClient(Cursor.Position)

hti = Me.HitTest(pt)

If Me.CurrentCell.RowNumber < rownumber Then

MessageBox.Show("This is a system row and it cannot be changed or deleted")

Return True

Exit Function

End If

If keydata = Keys.Delete And hti.Type = Me.HitTestType.RowHeader Then

If MessageBox.Show("Delete this row?", "Confirm Delete",
MessageBoxButtons.YesNo) = DialogResult.No Then

Return True

End If

End If

End Function

End Class

This works as long as they don't select more than one row. If two or more
rows are selected, including the one that can be deleted, the protected rows
get deleted as well.

I have also tried something like

Private Sub dtDS_RowDeleting(ByVal sender As Object, ByVal e As
System.Data.DataRowChangeEventArgs) Handles dtDS.RowDeleting

If dgDS.CurrentRowIndex < dgDS.rownumber Then

e.Row.RejectChanges()

End If

End Sub

but this rejectChanges does not stop the deletion.

Thanks in advance ...


Nov 21 '05 #1
0 983

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...
0
by: shravan | last post by:
Hi, I have a extended Windows Forms Datagrid, I have custom column styles defined for it. The problem is when I am in the new row and pressing escape two times - First time it's cancelling cell...
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...
1
by: GregM | last post by:
I have a read only datagrid that is designed to coordinate itself with textboxes. When the user clicks on a row in the datagrid, detailed data for that row is displayed for editing in 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...
1
by: mike | last post by:
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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.