在C#Windows应用程序中向DataGridView添加命令按钮 [英] Add Command Button to DataGridView in C# Windows Application

查看:97
本文介绍了在C#Windows应用程序中向DataGridView添加命令按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 In DataGridView 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆