using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.Sql; using System.Data.SqlClient; namespace DGV_ButtonEvent_WIN { public partial class Form1 : Form { DataSet ds = new DataSet(); DataTable dtInfo = new DataTable(); string strConn = "Server=.;Trusted_Connection=SSPI;Database=DBTRUCK;Enlist=false;"; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { SqlConnection conn = new SqlConnection(strConn); conn.Open(); string strSql = "SELECT * FROM CarFee"; SqlDataAdapter sda = new SqlDataAdapter(strSql, conn); sda.Fill(ds, "ds"); conn.Close(); dataGridView1.DataSource=ds.Tables[0]; } //dataGridView1事件 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { DataGridViewColumn column = dataGridView1.Columns[e.ColumnIndex]; if (column is DataGridViewButtonColumn) { //这里可以编写你需要的任意关于按钮事件的操作~ MessageBox.Show("按钮被点击"); } } } } }
datagridview 中添加了一个button类型的列,怎么写button的事件
最新推荐文章于 2023-09-19 13:45:42 发布