如何在运行时更改DataGridViewButtonColumn的文本 [英] How to change the text of DataGridViewButtonColumn at runtime

查看:77
本文介绍了如何在运行时更改DataGridViewButtonColumn的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的先生,



我在我的项目中使用Datagridview ..我已经按代码添加了列。

第一列是DataGridViewButtonColumn



 Dim colbtnUpdate As New DataGridViewButtonColumn 
使用colbtnUpdate
.Name =编辑
.HeaderText =编辑
.Text =编辑
.UseColumnTextForButtonValue = True
.Width = 50


结束DGV.Columns.Add(colbtnUpdate)



在运行时单击编辑按钮,然后按钮文本应更改为更新。

,它应该只更改为选定的行,剩余按钮的文本属性应保持与编辑相同。



我试过..但不工作..

请帮帮我..

谢谢..

解决方案

 私有  Sub  DGV_CellContentClick(发件人作为系统。对象,e  As  System.Windows.Forms.DataGridViewCellEventArgs)句柄 DGV.CellContentClick 
DGV.Columns(e.ColumnIndex).HeaderText = 更新
结束 Sub


 私人  Sub  DataGridView1_CellClick( ByVal  sender  As  对象 ByVal  e  As  System.Windows.Forms .DataGridViewCellEventArgs)句柄 DataGridView1.CellClick 
如果 Dat aGridView1.Columns(e.ColumnIndex).Name = ButtonColumn 然后
DataGridView1.CurrentCell.Value = ABCD
结束 如果
结束 Sub



还设置使用按钮值的列文本为true


< blockquote>您好。

只需处理DataGridView_CellContentClick事件:

并插入代码:



 私有  Sub  DataGridView1_CellContentClick(发件人 As  对象,e  As  DataGridViewCellEventArgs)句柄 DataGridVi ew1.CellContentClick 

' 检查点击的列是假装的
如果 DataGridView1.Columns(e.ColumnIndex).Name = 编辑 然后
Dim cel As DataGridViewButtonCell
' 检索点击的单元格
cel = CType (DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex),DataGridViewButtonCell)
' 更改值属性
cel.Value = 更新
结束 如果

结束 Sub





我测试过它的工作


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..

解决方案

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


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


Hi.
Just handle the DataGridView_CellContentClick event:
And insert code as this:

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


这篇关于如何在运行时更改DataGridViewButtonColumn的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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