using System;
using System.Windows.Forms;
using System.Drawing;
namespace DataGridView
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btn_Click(object sender, EventArgs e)
{
myDataGridView.Columns.Clear();
myDataGridView.ColumnCount = 2;
myDataGridView.Columns[0].Name = "User
ID";
myDataGridView.Columns[1].Name = "Password";
string[]
row = new string[]
{ "abc", "abc"};
myDataGridView.Rows.Add(row);
row = new string[]
{ "pqr", "pqr"};
myDataGridView.Rows.Add(row);
row = new string[]
{ "ghanashyam", "ghanashyam"};
myDataGridView.Rows.Add(row);
row = new string[]
{ "jignesh", "jignesh"};
myDataGridView.Rows.Add(row);
DataGridViewButtonColumn dgvButton
= new DataGridViewButtonColumn();
dgvButton.FlatStyle= FlatStyle.System;
dgvButton.HeaderText = "Button";
dgvButton.Name = "Button";
dgvButton.UseColumnTextForButtonValue = true;
dgvButton.Text = "New";
myDataGridView.Columns.Add(dgvButton);
}
private void myDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 2)
{
//Write here your code...
MessageBox.Show("You
Have Selected " + (e.RowIndex + 1).ToString() + "
Row Button");
}
}
}
} |