.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按钮的更多相关文章

  1. 如何在MFC界面开发中响应Button按钮的Down和Up事件

    通过尝试有两种方案可以解决这个问题,第一种方案是通过PreTranslateMessage函数在调度消息之前对消息类型进行筛选,第二种方案是重载CButton类,在重载后的类CForTestButto ...

  2. DataGridView 中添加CheckBox和常用处理方式 .

    DataGridView 中添加CheckBox和常用处理方式 文章1 转载:http://blog.csdn.net/pinkey1987/article/details/5267934 DataG ...

  3. DataGridView中添加CheckBox列用于选择行

    DataGridView中添加CheckBox列用于选择行 1,编辑DataGridView,添加一列 CheckBox ,Name 赋值为 "select",如下图: 2,取消 ...

  4. Visual Studio 2008中添加运行按钮 转载

    在Visual Studio 2008中添加运行按钮 默认情况下,VS2008中的工具栏上没有运行按钮,只有调试(Debug)按钮,可按照以下方法添加 1.点击菜单Tools(工具)->Cust ...

  5. android中在java代码中设置Button按钮的背景颜色

    android中在java代码中设置Button按钮的背景颜色 1.设置背景图片,图片来源于drawable: flightInfoPanel.setBackgroundDrawable(getRes ...

  6. Android处理ListView中的Item中的Button按钮不能点击的问题

    问题描述:ListView列表中的Button按钮按钮不能点击 解决办法:在ListView中的Item项的布局文件中加上:android:descendantFocusability="b ...

  7. 127使用 TableView 自带的单元格样式实现好友列表,另外在单元格中添加辅助按钮

    类似的做法如之前这篇随笔:114自定义UITableViewCell(扩展知识:为UITableViewCell添加动画效果) 相比之下:自定义 UITableViewCell 的内容灵活,可根据需求 ...

  8. 在QTableView中某列中添加Button的导致滚动条滚动的时候消失的问题

    之前在项目上需要在表格中加入Button是按照以下两个文章的做法: http://www.cnblogs.com/li-peng/p/3961843.html http://www.cnblogs.c ...

  9. 在excel worksheet中添加button 和对Excel workbook做权限控制相关的新知识

    添加button在worksheet中 1. Shapes Object (Excel) Reference:http://technet.microsoft.com/zh-cn/library/ff ...

随机推荐

  1. 浏览器缓存如何控制? && 在url框中回车、F5 和 Ctrl + F5的区别是什么?

    第一部分: 浏览器缓存如何控制?   最近在做网站,但是不知道缓存是什么东西怎么能行! 如何实现HTTP缓存呢? 下面我们来一步一步的探寻实现机制把. 方案一: 无缓存   说明: 浏览器向服务器请求 ...

  2. Thinkphp3.2.X自动生成应用目录

    从3.2.2版本开始,可以支持自动生成默认模块之外的模块目录以及批量生成控制器和模型类. 例如,如果我们需要生成一个Admin模块用于后台应用,在应用入口文件中定义如下: // 绑定Admin模块到当 ...

  3. vuex requires a Promise polyfill in this browser

    ie 浏览器访问 vue 项目(使用的vuex 状态管理组件)报错:vuex requires a Promise polyfill in this browser 处理办法: 1.npm insta ...

  4. css3圆形轨迹动画

    <!doctype html>      <html lang="en">      <head>          <meta char ...

  5. Struts dispatchAction

    在Struts中定义动态Action,不用定义多个Action,可以实现一个action,多个跳转. 在定义时,继承DispatchAction,并定义parameter的名字 在jsp页面选择act ...

  6. [转载]VS2010怎样打开VS2013或者VS2015建立的工程

    VS2010怎样打开VS2013或者VS2015建立的工程 作用:解决vs低版本无法直接打开高版本的工程文件问题. 一.转载出处 http://blog.csdn.net/qq2399431200/a ...

  7. *2_3_5_加入reference model

    摘自:http://book.2cto.com/201408/46009.html 在2.1节中讲述验证平台的框图时曾经说过,reference model用于完成和DUT相同的功能. referen ...

  8. c之指针与数组(2)Dynamic Data Structures: Malloc and Free--转载

    http://www.howstuffworks.com/c29.htm http://computer.howstuffworks.com/c.htm Dynamic Data Structures ...

  9. 关于css浮动框是否脱离文档流的分析

    在了解浮动属性之前,首先我们先了解一下html中关于display属性的相关知识. display属性常用的有inline, block, inline-block. inline也就是内联的意思. ...

  10. win10下设置IIS、安装php7.2

    开启IIS及相关功能: 控制面板——程序和功能——启用或关闭Windows功能——勾选Internet Information Service——万维网服务——性能和功能——勾选CGI 开启成功后在 ...