I'm trying to change the text of a button in a DataGridViewButtonColumn every time the button is clicked.
I define the column like so:
DataGridViewButtonColumn sitemapButtonColumn = new DataGridViewButtonColumn
{
Name = "Process",
Text = "Start",
UseColumnTextForButtonValue = true,
DataPropertyName = "Process",
FillWeight = 7,
Width = 75
};
dg_list.CellContentClick += dg_list_StartStopProcessClick;
Now the function which controls the event once a cell clicked is:
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;
}
}
}
Well, this does not work!
I've been googling and found a post which modifies UseColumnTextForButtonValue to false, set the new text value and set to true again.
The problem is that i can not figure out how can i get access to UseColumnTextForButtonValue property within the event.
Any help?