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 "); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)