C# 更改DataGridViewButtonColumn';s按钮每行文本数
我有一个C# 更改DataGridViewButtonColumn';s按钮每行文本数,c#,C#,我有一个DataGridView,其中一列的类型为DataGridView按钮column foreach (DataGridViewRow row in dataGridView1.Rows) { DataGridViewCell cell = row.Cells[0]; //Column Index for the dataGridViewButtonColumn cell.Value = "Your Text"; } 我想在按钮上加一条文字。我已经尝试在编辑列选
DataGridView
,其中一列的类型为DataGridView按钮column
foreach (DataGridViewRow row in dataGridView1.Rows)
{
DataGridViewCell cell = row.Cells[0]; //Column Index for the dataGridViewButtonColumn
cell.Value = "Your Text";
}
我想在按钮上加一条文字。我已经尝试在编辑列选项中将文本放入文本属性中。我甚至尝试过swtteUseColumnTextForButtonValue=true
foreach (DataGridViewRow row in dataGridView1.Rows)
{
DataGridViewCell cell = row.Cells[0]; //Column Index for the dataGridViewButtonColumn
cell.Value = "Your Text";
}
我找不到使其工作的方法。是否要将DataGridViewButtonColumn文本绑定到DataGridView的数据源?如果是,则通过编辑列选项设置列的DataPropertyName
foreach (DataGridViewRow row in dataGridView1.Rows)
{
DataGridViewCell cell = row.Cells[0]; //Column Index for the dataGridViewButtonColumn
cell.Value = "Your Text";
}
否则,您可以尝试使用DataGridView的CellFormatting事件:
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == 0)
{
e.Value = "some value";
}
}
foreach (DataGridViewRow row in dataGridView1.Rows)
{
DataGridViewCell cell = row.Cells[0]; //Column Index for the dataGridViewButtonColumn
cell.Value = "Your Text";
}
是否要将DataGridViewButtonColumn文本绑定到DataGridView的数据源?如果是,则通过编辑列选项设置列的DataPropertyName
foreach (DataGridViewRow row in dataGridView1.Rows)
{
DataGridViewCell cell = row.Cells[0]; //Column Index for the dataGridViewButtonColumn
cell.Value = "Your Text";
}
否则,您可以尝试使用DataGridView的CellFormatting事件:
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == 0)
{
e.Value = "some value";
}
}
foreach (DataGridViewRow row in dataGridView1.Rows)
{
DataGridViewCell cell = row.Cells[0]; //Column Index for the dataGridViewButtonColumn
cell.Value = "Your Text";
}
假设您的DataGridView名称为DataGridView1
foreach (DataGridViewRow row in dataGridView1.Rows)
{
DataGridViewCell cell = row.Cells[0]; //Column Index for the dataGridViewButtonColumn
cell.Value = "Your Text";
}
假设您的DataGridView名称为DataGridView1
foreach (DataGridViewRow row in dataGridView1.Rows)
{
DataGridViewCell cell = row.Cells[0]; //Column Index for the dataGridViewButtonColumn
cell.Value = "Your Text";
}
这应该被接受。注意:
e.Value
只是显示的内容,与单元格.Value
无关,它仍然可以是我们需要的任何内容,包括一个真正的按钮
:`Button btn=DGV[2,e.RowIndex]。值为按钮;如果(btn!=null)e.Value=btn.Text`这应该被接受。注意:e.Value
只是显示的内容,与单元格.Value
无关,它仍然可以是我们需要的任何内容,包括一个真正的按钮
:`Button btn=DGV[2,e.RowIndex]。值为按钮;如果(btn!=null)e.Value=btn.Text`