Sreedevi v

Sreedevi v

  • NA
  • 166
  • 5.3k

Add button dynamically in first column of DataGridView

Apr 12 2019 12:25 AM
int[] colWidth = {5,10, 17 };
string[] colAlign = { "C", "L", "L" };
string[] colTabStop = { "False", "True", "True" };
string[] Colheader = {"Sl No", "Product ID", "Product Name"};
 
 
private void initgrid()
{
DataTable dt = new DataTable();
dt = purchasesb.GetPEByNO("");
for (int i = 0; i < dt.Columns.Count; i++)
{
dgvdetails.Columns.Add(dt.Columns[i].ColumnName, Colheader[i]);
if (colAlign[i] == "R")
{
dgvdetails.Columns[i].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
dgvdetails.Columns[i].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight;
}
else if (colAlign[i] == "C")
{
dgvdetails.Columns[i].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
dgvdetails.Columns[i].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
}
else
{
dgvdetails.Columns[i].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
dgvdetails.Columns[i].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleLeft;
}
if (colTabStop[i] == "False")
{
dgvdetails.Columns[i].ReadOnly = true;
}
else
{
dgvdetails.Columns[i].ReadOnly = false;
}
dgvdetails.Columns[i].Width = Convert.ToInt32(((colWidth[i] * panel2.Size.Width) / 100));
}
}
 
This is my code.
How to add button dynamically in firstcolum((ie when i=0) of DataGridView- dgvdetails? 

Answers (1)