标签:
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Windows.Forms; 9 using System.Data.Sql; 10 using System.Data.SqlClient; 11 12 namespace DGV_ButtonEvent_WIN 13 { 14 public partial class Form1 : Form 15 { 16 DataSet ds = new DataSet(); 17 DataTable dtInfo = new DataTable(); 18 string strConn = "Server=.;Trusted_Connection=SSPI;Database=DBTRUCK;Enlist=false;"; 19 20 public Form1() 21 { 22 InitializeComponent(); 23 } 24 25 private void Form1_Load(object sender, EventArgs e) 26 { 27 SqlConnection conn = new SqlConnection(strConn); 28 conn.Open(); 29 string strSql = "SELECT * FROM CarFee"; 30 SqlDataAdapter sda = new SqlDataAdapter(strSql, conn); 31 sda.Fill(ds, "ds"); 32 conn.Close(); 33 dataGridView1.DataSource=ds.Tables[0]; 34 } 35 36 //dataGridView1事件 37 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) 38 { 39 if (e.RowIndex >= 0) 40 { 41 DataGridViewColumn column = dataGridView1.Columns[e.ColumnIndex]; 42 if (column is DataGridViewButtonColumn) 43 { 44 //这里可以编写你需要的任意关于按钮事件的操作~ 45 MessageBox.Show("按钮被点击"); 46 } 47 //DGV下拉框的取值 48 MessageBox.Show(dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex-1].Value.ToString()); 49 } 50 } 51 } 52 } 53 54
datagridview 中添加了一个button类型的列,怎么写button的事件
标签:
原文地址:http://www.cnblogs.com/gx-143/p/5792915.html