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
  1. Home
  2. General Programming
  3. Visual Basic
  4. deleting a row in a datagrid

deleting a row in a datagrid

Scheduled Pinned Locked Moved Visual Basic
question
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mcm
    wrote on last edited by
    #1

    to delete a row in a datagrid, i highlight the row and press a delete command button. this also works if i highlight the row and press delete on the keyboard. However, now i wish to perform calculations on the click of the delete command button. if delete on the keyboard is pressed, is there anyway to call the delete procedure? Thanks in advance!

    B 1 Reply Last reply
    0
    • M mcm

      to delete a row in a datagrid, i highlight the row and press a delete command button. this also works if i highlight the row and press delete on the keyboard. However, now i wish to perform calculations on the click of the delete command button. if delete on the keyboard is pressed, is there anyway to call the delete procedure? Thanks in advance!

      B Offline
      B Offline
      Brian Lehmann
      wrote on last edited by
      #2

      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!

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

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