如何在VB.NET中使用datagridview的图像按钮编辑,更新行数据? [英] How do I edit, update row data using image button of datagridview in VB.NET?

查看:129
本文介绍了如何在VB.NET中使用datagridview的图像按钮编辑,更新行数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在vb.net中找到DataGridView的解决方案



有一个带编辑和删除列的datagridview,带有用于编辑的图像按钮,作为行删除



现在如何在vb.net中选择gridview图像删除按钮后删除特定行

和编辑图像按钮的方式相同。



如果有人帮助我,请尽快帮助我。



谢谢。



我的尝试:



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:

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

推荐答案

您处理cellclick事件并删除单元格RowIndex位置上的行。



轻松在MS文档中 found example
You handle cellclick event and delete row on the cells RowIndex location.

On MS docs easily found example


这篇关于如何在VB.NET中使用datagridview的图像按钮编辑,更新行数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆