Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 更改DataGridViewButtonColumn';s按钮每行文本数_C# - Fatal编程技术网

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";
 }
我想在按钮上加一条文字。我已经尝试在编辑列选项中将文本放入文本属性中。我甚至尝试过swtte
UseColumnTextForButtonValue=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`