Click here to Skip to main content
15,883,623 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have find solution for DataGridView in vb.net

There is a one datagridview with edit and delete column with image buttons for edit,delete as a rows

Now how can i delete particular row after select gridview image delete button in vb.net
and same way for edit image button too.

if any one help me out then please help me ASAP.

Thank You.

What I have tried:

VB
Private Sub DataGridView1_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting
        If e.ColumnIndex = 3 AndAlso e.RowIndex >= 0 Then
            e.Paint(e.CellBounds, DataGridViewPaintParts.All)
            Dim img As Image = Image.FromFile("C:\Users\VP\Documents\Visual Studio 2008\Projects\vp\vp\Resources\1.png")
            e.Graphics.DrawImage(img, e.CellBounds.Left + 30, e.CellBounds.Top + 5, 10, 10)
            e.Handled = True


        ElseIf e.ColumnIndex = 4 AndAlso e.RowIndex >= 0 Then
            e.Paint(e.CellBounds, DataGridViewPaintParts.All)
            Dim img As Image = Image.FromFile("C:\Users\VP\Documents\Visual Studio 2008\Projects\vp\vp\Resources\1.png")
            e.Graphics.DrawImage(img, e.CellBounds.Left + 30, e.CellBounds.Top + 5, 10, 10)
            e.Handled = True
        End If
    End Sub

Private Sub viewplans_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim btnColumn As New DataGridViewButtonColumn()

        DataGridView1.Columns.Add(btnColumn)
        btnColumn.Name = "btnColumn"
        btnColumn.HeaderText = "Delete"

        Dim editcolumn As New DataGridViewButtonColumn()
        DataGridView1.Columns.Add(editcolumn)
        editcolumn.Name = "editcolumn"
        editcolumn.HeaderText = "Edit"
end sub
Posted
Updated 13-Sep-18 0:57am
v4
Comments
Sinisa Hajnal 13-Sep-18 6:59am    
You really shouldn't have hard-coded paths to images. Also, you can put images through properties of the grid instead of programatically adding everything. Play with grid properties, you'd be surprised what can be done without coding.

1 solution

You handle cellclick event and delete row on the cells RowIndex location.

On MS docs easily found example
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900