datagridview 中添加了一个button类型的列,怎么写button的事件
winform中 大家快看看啊,我在线等
//我写了一个简单的代码,希望对你誉渗有点帮助~~
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("按钮被点击唤耐");
}
}
}
}
}