Click here to Skip to main content
15,893,722 members
Please Sign up or sign in to vote.
4.27/5 (3 votes)
See more:
Respected Sir,

I am using Datagridview in my project..in which i have added columns by code.
in those columns one column is DataGridViewButtonColumn

Dim colbtnUpdate As New DataGridViewButtonColumn
With colbtnUpdate
    .Name = "Edit"
    .HeaderText = "Edit"
    .Text = "Edit"
    .UseColumnTextForButtonValue = True
    .Width = 50
End With

DGV.Columns.Add(colbtnUpdate)

at runtime when i do click on that "Edit" button then that Button text should be change to "Update".
and it should be changed to only that selected row and remaining button's text property should remains same as "Edit".

I have tried ..but not working..
Please help me..
Thank you..
Posted

VB
Private Sub DGV_CellContentClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGV.CellContentClick
       DGV.Columns(e.ColumnIndex).HeaderText = "Update"
   End Sub
 
Share this answer
 
Comments
Sunil Bansode 13-Dec-13 0:07am    
Its changes only header text of the column...
But i want to change the button text of clicked button
VB
Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
    If DataGridView1.Columns(e.ColumnIndex).Name = "ButtonColumn" Then
        DataGridView1.CurrentCell.Value = "ABCD"
    End If
End Sub

also set Use column text for button value as true
 
Share this answer
 
v2
Comments
brindhadevi 13-Mar-15 6:51am    
how to change the button text in grid view?
Hi.
Just handle the DataGridView_CellContentClick event:
And insert code as this:

VB
Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

'Check the clicked column is the pretended one
If DataGridView1.Columns(e.ColumnIndex).Name = "Edit" Then
   Dim cel As DataGridViewButtonCell
'retrieve clicked cell
   cel = CType(DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex), DataGridViewButtonCell)
'change value property
   cel.Value = "Update"
End If

End Sub


I tested and it work
 
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