Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7704909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:47:12+00:00 2026-05-31T23:47:12+00:00

Possible Duplicate: how to delete row from datagridview with a delete button? I have

  • 0

Possible Duplicate:
how to delete row from datagridview with a delete button?

I have System.Windows.Forms.DataGrid. How to delete selected row by delete button click? Selected row, not when cursor in cell!!!!!

If I click delete key on selected row it removes row immediately. I want to show dialog box here to confirm.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T23:47:13+00:00Added an answer on May 31, 2026 at 11:47 pm

    Here is the code for one that will raise an event to let you the user is about to delete a row.

    Public Class ConfirmDeleteDataGrid
    
    Inherits DataGrid
    
    Public Event DeletedRow(ByVal sender As Object, ByVal e As EventArgs)
    
    Private Const WM_KEYDOWN = &H100
    
    
    
    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 msg.Msg = WM_KEYDOWN And keyCode = Keys.Delete Then
    
    If MessageBox.Show("Delete This Row?", "Confirm Delete", _
    
    MessageBoxButtons.YesNo) = DialogResult.No Then
    
    Return True
    
    Else
    
    RaiseEvent DeletedRow(Me, New EventArgs)
    
    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 keyData = Keys.Delete Then
    
    If hti.Type = Me.HitTestType.RowHeader Then
    
    If MessageBox.Show("Delete this row?", "Confirm Delete", _
    
    MessageBoxButtons.YesNo) = DialogResult.No Then
    
    Return True
    
    Else
    
    RaiseEvent DeletedRow(Me, New EventArgs)
    
    End If
    
    End If
    
    End If
    
    Return MyBase.ProcessDialogKey(keyData)
    
    End Function
    
    
    
    Protected Overrides Sub OnMouseDown(ByVal e As
    System.Windows.Forms.MouseEventArgs)
    
    Dim hti As DataGrid.HitTestInfo = Me.HitTest(New Point(e.X, e.Y))
    
    If hti.Type = DataGrid.HitTestType.ColumnResize Or hti.Type =
    DataGrid.HitTestType.RowResize Then
    
    Return 'no baseclass call
    
    End If
    
    MyBase.OnMouseDown(e)
    
    End Sub
    
    Public Sub New()
    
    Trace.WriteLine(Me.VertScrollBar.Visible.ToString)
    
    End Sub
    
    Protected Overrides Sub OnMouseMove(ByVal e As
    System.Windows.Forms.MouseEventArgs)
    
    Dim hti As DataGrid.HitTestInfo = Me.HitTest(New Point(e.X, e.Y))
    
    If hti.Type = DataGrid.HitTestType.ColumnResize Or hti.Type =
    DataGrid.HitTestType.RowResize Then
    
    Return 'no baseclass call
    
    End If
    
    MyBase.OnMouseMove(e)
    
    End Sub
    
    
    End Class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: MySQL delete row from multiple tables I have 5 tables: members member_videos
Possible Duplicate: How to delete an element from an array in php? I have
Possible Duplicate: How to delete an element from an array in php? For instance,
Possible Duplicate: How to call a JavaScript function from PHP? I have a php
Possible Duplicate: Remove Duplicate Rows Leaving Oldest Row Only? I have a posts_table in
Possible Duplicate: Android ListView with delete button android Listview button Okay .. I will
Possible Duplicate: SQL Delete: can't specify target table for update in FROM clause I
Possible Duplicate: how to delete item from listView? I fetch data from Database in
Possible Duplicate: select multiple rows from uitableview and delete I am developing an application
Possible Duplicate: Direct access to DataGridView combobox in one click? I'm sure this behavior

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.