【发布时间】:2018-07-03 23:09:31
【问题描述】:
每次单击按钮时,我都会尝试更改 DataGridViewButtonColumn 中按钮的文本。
我这样定义列:
DataGridViewButtonColumn sitemapButtonColumn = new DataGridViewButtonColumn
{
Name = "Process",
Text = "Start",
UseColumnTextForButtonValue = true,
DataPropertyName = "Process",
FillWeight = 7,
Width = 75
};
dg_list.CellContentClick += dg_list_StartStopProcessClick;
现在控制单击单元格后事件的函数是:
private void dg_list_StartStopProcessClick(object sender, DataGridViewCellEventArgs e)
{
var senderGrid = (DataGridView)sender;
if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn &&
e.RowIndex >= 0 &&
e.ColumnIndex == dg_lista_blogs_automatizacion.Columns["Process"].Index)
{
if (senderGrid.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == "Start")
{
senderGrid.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = "Stop";
senderGrid.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor = Color.OrangeRed;
}
else
{
senderGrid.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = "Start";
senderGrid.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor = Color.White;
}
}
}
好吧,这行不通!
我一直在谷歌搜索,发现一个帖子将 UseColumnTextForButtonValue 修改为 false,设置新的文本值并再次设置为 true。
问题是我不知道如何在事件中访问 UseColumnTextForButtonValue 属性。
有什么帮助吗?
【问题讨论】:
标签: c# datagridviewcolumn datagridviewbuttoncolumn