查看MSDN帮助文档:

DataGridViewButtonCell 类是用于显示类似按钮的用户界面的专用类型的 DataGridViewCell

DataGridViewButtonColumn 专门用于保存此类型单元格的列类型。若要设置现有 DataGridViewButtonCell 之后的列中的单元格模式,请将此列的 CellTemplate 属性设置为该单元格。默认情况下,将 CellTemplate 初始化为新的 DataGridViewButtonCell

若要响应用户单击按钮,请处理 DataGridView.CellClickDataGridView.CellContentClick 事件。在事件处理程序中,可以使用 DataGridViewCellEventArgs.ColumnIndex 属性来确定单击是否发生在按钮列中。可以使用 DataGridViewCellEventArgs.RowIndex 属性来确定单击是否发生在特定按钮单元格中。

列的与单元格相关的属性是模板单元格的具有相似名称的属性的包装。更改模板单元格的属性值只会影响那些在更改之后添加的基于该模板的单元格。但是,更改列的与单元格相关的属性值将更新模板单元格和列中所有其他单元格,必要时还将刷新列显示。

 1 private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
2 {
3 if (e.ColumnIndex != -1)
4 {
5 if (this.dataGridView1.Columns[e.ColumnIndex].Name == "ColColor")//颜色显示按钮事件
6 {
7 //颜色
8 ColorDialog colordlg = new ColorDialog();
9 if (colordlg.ShowDialog(this)==DialogResult.OK)
10 {
11
12 DataGridViewCellStyle dgvCellStyle=new DataGridViewCellStyle() ;
13 dgvCellStyle.BackColor=colordlg.Color;
14 ((DataGridViewButtonCell)this.dataGridView1.Rows[e.RowIndex].Cells["ColColor"]).Style= dgvCellStyle;
15 }
16 }
17 }
18 }

 在给DataGridViewComboBoxCell增加事件是可以在EditingControlShowing 事件以将事件处理程序附加。

EditingControlShowing 事件以将事件处理程序附加到编辑控件的事件中。

注意——————————————————————————————————————————————

DataGridViewComboBoxEditingControl 类概述中的代码示例。

参考文献:

1.http://www.cnblogs.com/freeliver54/archive/2008/03/06/1093569.html

2.http://msdn.microsoft.com/zh-cn/library/system.windows.forms.datagridviewbuttoncell(v=VS.90)

3.http://www.cnblogs.com/lhxhappy/archive/2008/12/02/1345377.html

 

相关文章:

  • 2021-12-26
  • 2021-11-08
猜你喜欢
  • 2021-05-25
  • 2021-09-06
  • 2021-06-03
  • 2021-06-16
  • 2022-12-23
  • 2021-09-04
  • 2021-12-08
相关资源
相似解决方案