1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.ComponentModel;4 usingSystem.Data;5 usingSystem.Drawing;6 usingSystem.Linq;7 usingSystem.Text;8 usingSystem.Windows.Forms;9 usingSystem.Data.Sql;Ten usingSystem.Data.SqlClient; One A namespaceDgv_buttonevent_win - { - Public Partial classForm1:form the { -DataSet ds =NewDataSet (); -DataTable Dtinfo =NewDataTable (); - stringstrconn ="server=.; Trusted_connection=sspi;database=dbtruck; Enlist=false;"; + - PublicForm1 () + { A InitializeComponent (); at } - - Private voidForm1_Load (Objectsender, EventArgs e) - { -SqlConnection conn =NewSqlConnection (strconn); - Conn. Open (); in stringstrSQL ="SELECT * from Carfee"; -SqlDataAdapter SDA =NewSqlDataAdapter (strSQL, conn); toSda. Fill (DS,"DS"); + Conn. Close (); -Datagridview1.datasource=ds. tables[0]; the } * $ //DataGridView1 EventsPanax Notoginseng Private voidDatagridview1_cellcontentclick (Objectsender, DataGridViewCellEventArgs e) - { the if(E.rowindex >=0) + { ADataGridViewColumn column =Datagridview1.columns[e.columnindex]; the if(column isdatagridviewbuttoncolumn) + { - //Here you can write any action you need about the button event ~ $MessageBox.Show ("button is clicked"); $ } - //DGV The value of the drop-down box -MessageBox.Show (Datagridview1.rows[e.rowindex]. cells[e.columnindex-1]. Value.tostring ()); the } - }Wuyi } the } - Wu
DataGridView added a button type column, how to write the button event