Hi All,
I have one datagrid(Win Forms)where i will create two columns dynamically(run time) as Edit and Delete and also i am loading two buttons as same name. Here i am assigning datasource as data table. If i click onEdit & Delete Buttonssome times it fires the event (
CellContentClick). In some time it will not at all fires that event. Please help me in this. I have written code like this. Here upto 14 columns data will be loaded programatically(not dynamically).
For Loading columns and Buttons code is:
DataGridViewButtonColumn dtgvEdit = new DataGridViewButtonColumn();
dtgvEdit.Name = "btnEdit";
dtgvEditHeaderText = "Edit";
dtgvEdit.Text = "Edit";
dtgvEdit.UseColumnTextForButtonValue = true;
gridview.Columns.Insert(15, dtgvEdit);
DataGridViewButtonColumn dtgvDelete = new DataGridViewButtonColumn();
dtgvDelete.Name = "btnDelete";
dtgvDeleteHeaderText = "Delete";
dtgvDelete.Text = "Delete";
dtgvDelete.UseColumnTextForButtonValue = true;
gridview.Columns.Insert(16, dtgvDelete);
In CellContent click i have written code like this:
private
void dtgvExperience_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex==15 && e.RowIndex != -1)
{
exp.EmployerName = dtgvExperience.Rows[e.RowIndex].Cells[0].Value.ToString();
}
}