我正在尝试将所有按钮的文本设置为“设置文本”。我做了这个,但没有用……我该怎么做?
foreach (DataGridViewButtonCell btn in dataGridView1.Rows)
{
btn.Text = "Set Text";
}
此外,我如何为这些按钮设置 onclick 事件?
请您参考如下方法:
试试这个:
private void button1_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
DataGridViewCell cell = row.Cells[0];//Column Index
cell.Value = "Set Text";
}
}
结果:
对于点击事件:
private void gw_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 0)//Column index
{
//Do Somethings
}
}
