Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
B

Brian Lehmann

@Brian Lehmann
About
Posts
2
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • deleting a row in a datagrid
    B Brian Lehmann

    If I'm following you correctly, what you're wanting to do is capture the delete keypress for the datagrid. The only useful way I've found for doing this is to inherit your own datagrid and then override PreProcessMessage to check for the delete key. I use this to confirm deletion before actually carrying it out. The class looks something like this:

    Public Class DataGridConfirm > Inherits DataGrid 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 this is a "KeyDown" message and the key pressed was "Delete" ' then we need to verify that the user actually wants to delete ' the record by presenting a messagebox ' Win32.Msg.WM_KEYDOWN just points to an Enum: WM_KEYDOWN=&H100 If msg.Msg = Win32.Msg.WM_KEYDOWN And keyCode = Keys.Delete Then > > > > > If ((MessageBox.Show("Are you sure you want to delete?", "AppTitle", _ MessageBoxButtons.YesNo)) = DialogResult.No) Then ' They've selected no, so simply return Return True End If > > > > End If ' If the user has not canceled the request, flow into the normal ' message processing of the base control Return MyBase.PreProcessMessage(msg) > > End Function End Class

    After creating this class, just substitute it for the regular DataGrid your currently using.

    Hope that helps!

    Visual Basic question

  • Use of apostrophe in string
    B Brian Lehmann

    You may want to think about using a parameterized query to pass the values into your SQL statement. Using the SQL Server data provider, it would look something like this:

    Dim sql As String = "INSERT INTO Test (lname) VALUES (@LastName);" Dim cn As New SqlConnection(cnString) Dim cmd As New SqlCommand(sql, cn) cmd.Parameters.Add("@LastName", SqlDbType.VarChar).Value = Me.TextBox2.Text cn.Open() cmd.ExecuteNonQuery() cn.Close()

    Doing it this way will save you the trouble of replacing characters in each input field and will help protect against some forms of SQL Injection attacks. However, it won't get you out of validating input for other constraints such as length, etc.

    Hope that helps!

    Visual Basic database collaboration help
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups