Add a context menu to sfDataGrid in vb.net

Hi,

I need help how to add a context menu in sfDataGrid then right clicking on rowheader. The context menu should show 'Delete row'. There is an sample in C but I need help in a vb.net sample.


I can delete a row by clicking on rowheader and press Delete, using RecordDeleting.

AddHandler grid1.RecordDeleting, AddressOf grid1_RecordDeleting


But I also need a context menu to delete rows.

grid1.RowHeaderContextMenu = New ContextMenuStrip()

grid1.RowHeaderContextMenu.Items.Add("Delete row", Nothing, DeletedClick)


The DeletedClick event should call grid1_RecordDeleting so Delete key or right mouseclick will call the same routine RecordDeleting.


    Public Sub DeletedClick(ByVal sender As Object, e As MouseEventArgs)

        Dim ex As RecordDeletingEventArgs = Nothing

        grid1_RecordDeleting(sender, ex)

    End Sub


I got two errors I can not solve,

Argument not specified for parameter 'sender' of public sub DeletedClick(Sender as Object, e as MouseEventArgs)

Argument not specified for parameter 'e' of public sub DeletedClick(Sender as Object, e as MouseEventArgs)



1 Reply

VS Vijayarasan Sivanandham Syncfusion Team January 24, 2022 03:38 PM UTC

Hi Thomas Ellingsen,

Based on provided information your reported problem occurs due to mismatched event args type passed in DeletedClick event. You can resolve this problem by passing the EventArgs in ContextMenu event. Please refer the below code snippet,

 
Me.sfDataGrid1.RowHeaderContextMenu.Items.Add("Delete row", Nothing, AddressOf OnDeleteClicked) 
 
Private Sub OnDeleteClicked(sender As Object, e As EventArgs) 
 
                Dim ex As RecordDeletingEventArgs = Nothing 
 
                OnRecordDeleting(sender, ex) 
 
                'delete the record in SfDataGrid 
                employeeCollection.Rows.RemoveAt(0) 
End Sub 

Regards, 
Vijayarasan S

Loader.
Up arrow icon