Right Click Menu On DataGridView

How to right click on any row of databagridview and call a menu which consists of delete and update? Thank you.
[111 byte] By [lucerias] at [2007-12-29]
# 1

first

select context menu strip from toolbox in VS IDE 2005..... drag into form..default name as "context menu strip1" add items like delete,update......

2.add datagrid or gridview to form

3.in grid view property window select contextmenu and choose "context menu strip1"

4.Now select context menu strip click on any items go code window..

in your case try this for delete

Private Sub DeleteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeleteToolStripMenuItem.Click

Dim con As New SqlConnection

con = 'your connection string'

con.Open()

Dim a As Integer

Dim str As String

a = DataGrid1.CurrentRowIndex

str = "delete * from class where id = '" + DataGrid1(a, 0) + "' "

Dim cmd As New SqlCommand(str, con)

cmd.ExecuteNonQuery()

con.Close()

End Sub

try for update also .....

hsivaram at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2

first

select context menu strip from toolbox in VS IDE 2005..... drag into form..default name as "context menu strip1" add items like delete,update......

2.add datagrid or gridview to form

3.in grid view property window select contextmenu and choose "context menu strip1"

4.Now select context menu strip click on any items go code window..

in your case try this for delete

Private Sub DeleteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeleteToolStripMenuItem.Click

Dim con As New SqlConnection

con = 'your connection string'

con.Open()

Dim a As Integer

Dim str As String

a = DataGrid1.CurrentRowIndex

str = "delete * from class where id = '" + DataGrid1(a, 0) + "' "

Dim cmd As New SqlCommand(str, con)

cmd.ExecuteNonQuery()

con.Close()

End Sub

here class is table name id is first coloumn of table....

try for update also .....

hsivaram at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic Language...