Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
Hello,
 
I've c# app, and I'm using datagridview with button ,but the event that I put didn't work which is when you press the button something happens?
 
I used the code from
http://csharp.net-informations.com/datagridview/csharp-datagridview-button.htm[^]
 
private void ShowProduct_Load(object sender, EventArgs e)
        {
            con.ConnectionString = connection.x;
            try
            {
                con.Open();
                cmd = new SqlCommand("select product_id,product_name,Product_description,product_unitprice,product_sellingprice,product_quantity,total,vendor from product", con);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                da.Fill(dt);
                dataGridView1.DataSource = dt;
                dataGridView1.ReadOnly = true;
                DataGridViewButtonColumn btn = new DataGridViewButtonColumn();
                dataGridView1.Columns.Add(btn);
                btn.HeaderText = "Click Data";
                btn.Text = "Click Here";
                btn.Name = "btn";
                btn.UseColumnTextForButtonValue = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                if (cmd != null)
                {
                    cmd.Dispose();
                    cmd = null;
                }
                con.Close();
            }
        }
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 8)
            {
                MessageBox.Show((e.RowIndex + 1) + "  Row  " + (e.ColumnIndex + 1) + "  Column button clicked ");
            }
        }
Posted 19-Dec-12 0:06am
Comments
jibesh at 19-Dec-12 6:34am
   
why datagridview is readOnly. comment that code and see what is happening.
Member 8584763 at 19-Dec-12 10:32am
   
Nothing changes after commenting it?

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 19 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100