在datagridview中添加button按钮
.Net的DataGridView控件中,提供了一种列的类型,叫 DataGridViewButtonColumn ,这种列类型是展示为一个 按钮,可以给button赋予相应的text,并且,此button可以用来做处理事件的判断依据。
DataGridViewButtonColumn,虽然在UI展现上,是一个BUTTON的样子,但是,它的实际形态,并不是传统意义的BUTTON,而是渲染出来的样式,完全是painting的效果而已。所以,对于传统意义的BUTTON的那一套在这里都失效啦
代码实现:
//在datagridview中添加button按钮
DataGridViewButtonColumn btn = new DataGridViewButtonColumn();
btn.Name = "btnModify";
btn.HeaderText = "修改";
btn.DefaultCellStyle.NullValue = "修改";
dataGridView1.Columns.Add(btn);
然后在DataGridView的CellContentClick事件中写类似如下代码:
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
//点击button按钮事件
if (dataGridView1.Columns[e.ColumnIndex].Name == "btnModify" && e.RowIndex >= )
{
//说明点击的列是DataGridViewButtonColumn列
DataGridViewColumn column = dataGridView1.Columns[e.ColumnIndex];
IPEntity ipentity = new IPEntity(); ipentity.ipName = Convert.ToString(dataGridView1.CurrentRow.Cells[].Value);
ipentity.ipPart = Convert.ToString(dataGridView1.CurrentRow.Cells[].Value);
ipentity.ipStart = Convert.ToString(dataGridView1.CurrentRow.Cells[].Value);
ipentity.ipEnd = Convert.ToString(dataGridView1.CurrentRow.Cells[].Value); bool flag = selectIp.UpdateIP(ipentity);
if (flag)
{
MessageBox.Show("更新成功!");
}
else
{
MessageBox.Show("更新失败!");
}
}
}
在datagridview中添加button按钮的更多相关文章
- 如何在MFC界面开发中响应Button按钮的Down和Up事件
通过尝试有两种方案可以解决这个问题,第一种方案是通过PreTranslateMessage函数在调度消息之前对消息类型进行筛选,第二种方案是重载CButton类,在重载后的类CForTestButto ...
- DataGridView 中添加CheckBox和常用处理方式 .
DataGridView 中添加CheckBox和常用处理方式 文章1 转载:http://blog.csdn.net/pinkey1987/article/details/5267934 DataG ...
- DataGridView中添加CheckBox列用于选择行
DataGridView中添加CheckBox列用于选择行 1,编辑DataGridView,添加一列 CheckBox ,Name 赋值为 "select",如下图: 2,取消 ...
- Visual Studio 2008中添加运行按钮 转载
在Visual Studio 2008中添加运行按钮 默认情况下,VS2008中的工具栏上没有运行按钮,只有调试(Debug)按钮,可按照以下方法添加 1.点击菜单Tools(工具)->Cust ...
- android中在java代码中设置Button按钮的背景颜色
android中在java代码中设置Button按钮的背景颜色 1.设置背景图片,图片来源于drawable: flightInfoPanel.setBackgroundDrawable(getRes ...
- Android处理ListView中的Item中的Button按钮不能点击的问题
问题描述:ListView列表中的Button按钮按钮不能点击 解决办法:在ListView中的Item项的布局文件中加上:android:descendantFocusability="b ...
- 127使用 TableView 自带的单元格样式实现好友列表,另外在单元格中添加辅助按钮
类似的做法如之前这篇随笔:114自定义UITableViewCell(扩展知识:为UITableViewCell添加动画效果) 相比之下:自定义 UITableViewCell 的内容灵活,可根据需求 ...
- 在QTableView中某列中添加Button的导致滚动条滚动的时候消失的问题
之前在项目上需要在表格中加入Button是按照以下两个文章的做法: http://www.cnblogs.com/li-peng/p/3961843.html http://www.cnblogs.c ...
- 在excel worksheet中添加button 和对Excel workbook做权限控制相关的新知识
添加button在worksheet中 1. Shapes Object (Excel) Reference:http://technet.microsoft.com/zh-cn/library/ff ...
随机推荐
- vSphere通过Client创建Centos7主机
准备: vSphere Client 客户端 Centos7官方镜像,本次采用的是CentOS-7-x86_64-Minimal-1511.iso 创建过程: 1.登录vSphere虚拟主机,输入账户 ...
- 高性能队列Disruptor的使用
一.什么是 Disruptor 从功能上来看,Disruptor 是实现了"队列"的功能,而且是一个有界队列.那么它的应用场景自然就是"生产者-消费者"模型的应 ...
- JavaScript数据结构-8.双向链表
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- JavaScript设计模式-11.桥梁模式
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- leetcode简单题目两道(5)
Problem Given an integer (signed bits), write a function to check whether it . Example: Given num = ...
- [转]RDL(C) Report Design Step by Step 3: Mail Label
本文转自:http://www.cnblogs.com/waxdoll/archive/2006/09/02/493350.html Crystal Report在报表向导中提供了三种向导类型给用户进 ...
- SSIS教程:创建简单的ETL包 -- 6. 对项目部署模型使用参数(Using Parameters with the Project Deployment Model)
在本课中,将修改在第 5 课: 添加包部署模型的包配置中创建的包,以便使用项目部署模型.您将使用一个参数替换该配置值,以便指定示例数据位置.还可以复制本教程附带的已完成的 Lesson 5 包. 使用 ...
- tomcat的8088端口被占用
打开Dos:windows->输入cmd(想必这个都会) 在黑窗口中输入指令:netstat -ano | findstr 8080 指令的意思是找出占用8080端口的进程pid 再 ...
- [javaSE] 多线程(售票例子)
需求:简单的买票程序,多个窗口卖票,多线程 定义一个类Ticket实现Runnable接口, 定义成员属性int类型的票数nums 实现run()方法,run方法中 while(true)的死循环,打 ...
- Java学习--jsp基础语法
<%! %>和<% %>的区别: <%! //1.可定义方法 //2.可定义static方法 //3.可定义static属性 //4.不可以使用out对象 %> ...