DataGridView added a button type column, how to write the button event

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.