473,837 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

OleDbCommandbui lder... how to disable DELETE?

I have a datagrid that successfully allows editing and updating (with
dataadapter.upd ate command). I want the user to be able to edit the
"text" in the datagrid, but i DON'T want the user to be able to DELETE
rows.

The OleDbCommandBui lder automatically creates the DELETE SQL statement.
Is there any way I can disable it? If not, what approach should I be
using?

Thanks!
John

Nov 21 '05 #1
1 1952
Hi,

You need to create an inherited datagrid for that. Here is the code
for one that will raise an event to let you the user is about to delete a
row. Also prevents the user from resizing a row or column.

Public Class ConfirmDeleteDa taGrid

Inherits DataGrid

Public Event DeletedRow(ByVa l sender As Object, ByVal e As EventArgs)

Private Const WM_KEYDOWN = &H100

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

Dim keyCode As Keys = CType((msg.WPar am.ToInt32 And Keys.KeyCode), Keys)

If msg.Msg = WM_KEYDOWN And keyCode = Keys.Delete Then

If MessageBox.Show ("Delete This Row?", "Confirm Delete", _

MessageBoxButto ns.YesNo) = DialogResult.No Then

Return True

Else

RaiseEvent DeletedRow(Me, New EventArgs)

End If

End If

Return MyBase.PreProce ssMessage(msg)

End Function

Protected Overrides Function ProcessDialogKe y(ByVal keyData As
System.Windows. Forms.Keys) As Boolean

Dim pt As Point

Dim hti As DataGrid.HitTes tInfo

pt = Me.PointToClien t(Cursor.Positi on)

hti = Me.HitTest(pt)

If keyData = Keys.Delete Then

If hti.Type = Me.HitTestType. RowHeader Then

If MessageBox.Show ("Delete this row?", "Confirm Delete", _

MessageBoxButto ns.YesNo) = DialogResult.No Then

Return True

Else

RaiseEvent DeletedRow(Me, New EventArgs)

End If

End If

End If

Return MyBase.ProcessD ialogKey(keyDat a)

End Function

Protected Overrides Sub OnMouseDown(ByV al e As
System.Windows. Forms.MouseEven tArgs)

Dim hti As DataGrid.HitTes tInfo = Me.HitTest(New Point(e.X, e.Y))

If hti.Type = DataGrid.HitTes tType.ColumnRes ize Or hti.Type =
DataGrid.HitTes tType.RowResize Then

Return 'no baseclass call

End If

MyBase.OnMouseD own(e)

End Sub

Public Sub New()

Trace.WriteLine (Me.VertScrollB ar.Visible.ToSt ring)

End Sub

Protected Overrides Sub OnMouseMove(ByV al e As
System.Windows. Forms.MouseEven tArgs)

Dim hti As DataGrid.HitTes tInfo = Me.HitTest(New Point(e.X, e.Y))

If hti.Type = DataGrid.HitTes tType.ColumnRes ize Or hti.Type =
DataGrid.HitTes tType.RowResize Then

Return 'no baseclass call

End If

MyBase.OnMouseM ove(e)

End Sub
End Class

Ken

-------------------------------
"johnb41" <or****@informa tik.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
I have a datagrid that successfully allows editing and updating (with
dataadapter.upd ate command). I want the user to be able to edit the
"text" in the datagrid, but i DON'T want the user to be able to DELETE
rows.

The OleDbCommandBui lder automatically creates the DELETE SQL statement.
Is there any way I can disable it? If not, what approach should I be
using?

Thanks!
John
Nov 21 '05 #2

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

Similar topics

5
5926
by: Greg | last post by:
I am developing an application where I need to secure a workstation for periods of time. I can use BlockInput to stop users from task switching or messing with the keyboard, but I would like to disable Ctrl-Alt-Delete. It seems there seems to be only one real way I know about: Write a replacement Gina Driver to eat the keyboard events I dont want. Does anyone have a good template for this in Visual Basic .Net?
1
2930
by: Geroge D. Lake | last post by:
Hi, I need to disable the resizing of a datagrid. I have tried al day and no luck. Any Ideas? Thanks. George.
2
4746
by: Josema | last post by:
Hi to all, Im getting an error that in theory is simple but i dont understand... This is the line when i get the error, and the oledbcmd is well created, with the connection opened, the command text set to GetScheduledGames, and the CommandType set to Stored procedure... Im querying against ms- access OleDbCommandBuilder.DeriveParameters(this.oledbcmd);
1
2722
by: keithb | last post by:
I have a GridView control that has a delete button (hyperlink) in one column. The datasource table contains a column that has a true/false indicator showing whether or not the record can be deleted. How can I enable/disable the delete button depending on the value of the indicator? Ideally, I would like to make the button invisible where a record cannot be deleted. Thanks, Keith
7
1736
by: Paul | last post by:
I'm trying to update a Microsoft Access database. I can successfully read from the database and submit a command to DELETE all records from a table. Now I'm trying to add records to the table that I just cleared. Below is the code: myConnection = New OleDb.OleDbConnection(accessConnectionStringConstant & accessMdb) myCommand.Connection = myConnection myCommand.CommandText = SqlString
3
11669
by: Pietro | last post by:
Hi all, First of all I'd like to thank you very very much ,as finally after many years of searching,I could find a code to disable/enable the shift key,but actually i cannot use the code as I'm very new to VBA,i tried to follow the instructions reported in the code,but i got no result,i still can use the shift key,can you explain in details how to use it correctly to enable/disable users from pressing shift key to view database windw?,the...
3
3929
by: Bob Alston | last post by:
Anyone know how to disable or redefine the Ctrl - hotkey which deletes a record? I have a multi page form that uses 14 records, each record handles 1-2 pages of the 18 page form. Occasionally , after being there initially, one of the records becomes deleted. I have found I can cause this by pressing CTRL and the MINUS key simultaneously. Even the confirm delete doesn't work. Any way to redefine the function of CTRL + MINUS? Bob
2
1734
by: triffid | last post by:
Hi there, I'm trying to update my database via an UPDATE from OleDbCommandBuilder. This is the second time I've tried, and I'm still not having any luck. I've almost certainly missed something obvious, but having searched for quite a while, I don't know what it is(!) The code is here (intentionally showing source rather than having server run page):- http://home.freeuk.com/misacham/temp/ASPX_COMMAND_BUILDER_UPDATE.aspx
0
989
by: =?Utf-8?B?QTdtYWQ=?= | last post by:
Hi all, I'm using OleDbCommandBuilder to build commands for an OleDbDataAdapter automatically The problem is when using OleDbDataAdapter to retrieve data from a "View" in a SQL Express database Ex: OleDbDataAdapter("select * from ViewName", ConnectionString); The generated CommandText for generated commands is invalid, it looks like
0
9846
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10890
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10581
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10634
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10279
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9416
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5855
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4053
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3127
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.