C# 在DataGridView中查找按钮控件
如何在DataGridView中找到按钮控件,我将在asp.net for GridView中执行类似的操作C# 在DataGridView中查找按钮控件,c#,.net,winforms,datagridview,C#,.net,Winforms,Datagridview,如何在DataGridView中找到按钮控件,我将在asp.net for GridView中执行类似的操作 foreach (GridViewRow row in gridviewname.Rows) { Button btnColor= (Button)row.FindControl("btnColor"); } 但我无法在Windows窗体应用程序中执行同样的操作。基本上,我正在尝试设置按钮的属性,如颜色、文本等 如果不需要更改单个按钮,则可以通
foreach (GridViewRow row in gridviewname.Rows)
{
Button btnColor= (Button)row.FindControl("btnColor");
}
但我无法在Windows窗体应用程序中执行同样的操作。基本上,我正在尝试设置按钮的属性,如颜色、文本等
buttonColumn = (DataGridViewButtonColumn)dataGridView.Columns
.Where(column => column is DataGridViewButtonColumn)
.First();
在
datagridview
中,您可以通过列获取按钮
this.mydatagridview.Columns("MybuttonColumn").DefaultCellStyle
或者,如果您有预定义的列,则:
this.MyButtonColumn.DefaultCellStyle
或者,如果使用Visual Studio designer,则可以通过designer设置列样式值 你能用这个代码做个小演示吗?
this.MyButtonColumn.DefaultCellStyle