在C#Windows应用程序中向DataGridView添加命令按钮 [英] Add Command Button to DataGridView in C# Windows Application
问题描述
Hello Team,
我正在开发一个Windows表单应用程序,其中 -
我想在<$上添加命令按钮c $ c> DataGridView 仅限几行。
在 DataGridView
中有列命名 - 状态。如果状态为打开,那么我希望看到按钮可见。对于其他单元格,我不希望按钮可见。
我动态刷新datagridview。
我有以下代码添加按钮列 -
Hello Team,
I am developing one Windows form application in which -
I would like to add Command Button on DataGridView
only for few rows.
In DataGridView
there is Column Named - "Status". If Status is Open then I want see Button to be visible. and for other cells I don't want button to be visible.
I am refreshing datagridview dynamically.
I have below code to add Button Column -
DataGridViewButtonColumn btn = new DataGridViewButtonColumn();
dataGridView1.Columns.Add(btn);
btn.HeaderText = "";
btn.Text = "Delete";
btn.Name = "btn";
btn.UseColumnTextForButtonValue = true;
请帮忙。
Please help.
推荐答案
使用按钮添加列DataGridView
动态
遵循此代码< br $>
To Add Column With Button InDataGridView
Dynamically
Follow this Code
DataGridViewButtonColumn bcol = new DataGridViewButtonColumn();
bcol.HeaderText = "Button Column ";
bcol.Text = "Click Me";
bcol.Name = "btnClickMe";
bcol.UseColumnTextForButtonValue = true;
dataGridView1.Columns.Add(bcol);
和处理单击按钮事件
And For Handling Click Event of Button
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 1)
{
//StateMents you Want to execute to Get Data
}
}
快乐编码:)
Happy Coding :)
这篇关于在C#Windows应用程序中向DataGridView添加命令按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!