---
title: "How can i edit row data using single row image click in vb.net Data Gridview"  
description: "How can i edit row data using single row image click in vb.net Data Gridview"  
author: "Vishu P"  
published: 2018-09-16  
updated: 2023-07-06  
canonical: https://www.mindstick.com/forum/34670/how-can-i-edit-row-data-using-single-row-image-click-in-vb-dot-net-data-gridview  
category: "vb.net"  
tags: ["vb.net", "datagridview"]  
reading_time: 3 minutes  

---

# How can i edit row data using single row image click in vb.net Data Gridview

[Private](https://www.mindstick.com/blog/11097/java-access-modifiers-the-public-and-the-private-modifiers) Sub viewplans_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

con.Open()

da = New OleDbDataAdapter("[select](https://www.mindstick.com/forum/160534/orderby-then-select-vs-select-then-orderby-performance)* from plandetails", con)

Dim cb As New OleDbCommandBuilder

cb = New OleDbCommandBuilder(da)

dt = New [DataTable](https://www.mindstick.com/blog/195/datatable-in-ado-dot-net)()

da.Fill(dt)

DataGridView1.DataSource = dt

DataGridView1.Columns(0).HeaderCell.Value = "ID" \

DataGridView1.Columns(0).Width = 60

DataGridView1.Columns(1).HeaderCell.Value = "Name"

DataGridView1.Columns(1).Width = 100

DataGridView1.Columns(2).HeaderCell.Value = "Rate"

DataGridView1.Columns(2).Width = 80

Dim editcol As New DataGridViewImageColumn \

editcol.Image = Image.FromFile("C:\Users\VP\[Documents](https://www.mindstick.com/articles/156931/the-main-types-of-business-documents)\[Visual Studio](https://www.mindstick.com/articles/12378/visual-studio-for-mac-is-out-of-beta-preview-now-officially-available) 2008\[Projects](https://www.mindstick.com/articles/105927/how-to-excel-at-managing-multiple-projects)\GTPL SOFT\GTPL SOFT\[Resources](https://yourviews.mindstick.com/view/293/renovation-causes-wastage-of-resources)\edit.png")

editcol.DefaultCellStyle.SelectionBackColor = System.Drawing.Color.White

DataGridView1.Columns.Add(editcol)

editcol.Name = "editcol"

editcol.HeaderText = "Edit"

editcol.Width = 70

Dim delatecol As New DataGridViewImageColumn \

' Dim img As Image

delatecol.Image = Image.FromFile("C:\Users\VP\Documents\Visual Studio 2008\Projects\GTPL SOFT\GTPL SOFT\Resources\[delete](https://www.mindstick.com/forum/33620/how-to-delete-record-from-list-in-mvc-using-ajax).png")

delatecol.DefaultCellStyle.SelectionBackColor = System.Drawing.Color.White

DataGridView1.Columns.Add(delatecol)

delatecol.Name = "delatecol"

delatecol.HeaderText = "Delete"

delatecol.Width = 70

con.Close() \

End Sub\

Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

'HOW CAN I EDIT SINGLE IMAGE ROW OF EDIT [COLUMN](https://www.mindstick.com/forum/33860/how-to-calculate-column-summary-in-sql-server) USING CELLCONTENT CLICK

End Sub

\

## Replies

### Reply by Aryan Kumar

Sure, I can help you with that. Here are the steps on how to edit row data using single row image click in VB.NET data gridview:

1. Create a new image button and set its ImageUrl property to the path of the image you want to use.
2. Add the image button to the GridView control.
3. Set the ImageButton's CommandName property to "Edit".
4. Add an event handler for the ImageButton's Click event.
5. In the event handler, get the selected row from the GridView control.
6. Bind the data from the selected row to the form controls.
7. Enable the form controls so that the user can edit the data.
8. When the user clicks the Save button, save the changes to the data.

Here is an example of the code you would need to edit row data using single row image click in VB.NET data gridview:

VB.Net

```plaintext
Private Sub ImageButton1_Click(sender As Object, e As EventArgs) Handles ImageButton1.Click
    ' Get the selected row from the GridView control.
    Dim selectedRow As GridViewRow = GridView1.SelectedRow

    ' Bind the data from the selected row to the form controls.
    txtID.Text = selectedRow.Cells(0).Text
    txtName.Text = selectedRow.Cells(1).Text
    txtEmail.Text = selectedRow.Cells(2).Text

    ' Enable the form controls so that the user can edit the data.
    txtID.Enabled = True
    txtName.Enabled = True
    txtEmail.Enabled = True
End Sub
```

This code will create an image button and bind it to the GridView control. When the user clicks the image button, the code will get the selected row from the GridView control and bind the data from the selected row to the form controls. The form controls will then be enabled so that the user can edit the data. When the user clicks the Save button, the code will save the changes to the data.


---

Original Source: https://www.mindstick.com/forum/34670/how-can-i-edit-row-data-using-single-row-image-click-in-vb-dot-net-data-gridview

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
