Home Forums WinForms controls Xceed Grid for WinForms How to delete a row when the Delete key is pressed

Viewing 1 post (of 1 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #17816 |

    Any row can be deleted from the grid using the row’s Remove method, however rows will not be automatically deleted when the delete key is pressed. In order to delete rows from the grid when the delete key is pressed, you need to handle the KeyDown event of the DataRowTemplate (for each DataRow in the grid) and the KeyDown event of any other row that you want to allow your end-users to delete. In the event handler, you can then check if the key that was pressed is the delete key and then remove the row from the grid.

    In the following example, we check to see if it was the delete key that was pressed. If it was, we check to make sure that the row is a DataRow and then we delete the row. The validation to check if the row is a DataRow is not necessary; Any type of row can be deleted using the Remove method.

    VB.NET

    If e.KeyData = Keys.Delete Then
      If TypeOf sender Is Xceed.Grid.DataRow Then
        CType(sender, Xceed.Grid.DataRow).Remove()
      End If
    End If

    C#

    if( e.KeyData == Keys.Delete )
    {
      if( sender is Xceed.Grid.DataRow )
      {
        ( ( Xceed.Grid.DataRow )sender ).Remove();
      }
    }

    Imported from legacy forums. Posted by Xceed admin (had 952 views)

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.