Code Snippet
public partial class Form17 : Form
{
public Form17()
{
InitializeComponent();
}
private void Form17_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("id");
dt.Columns.Add("item");
for (int i = 0; i < 50; i++)
{
dt.Rows.Add(i, "item" + i);
}
dt.AcceptChanges();
DataGridViewButtonColumn btnColumn = new DataGridViewButtonColumn();
btnColumn.DataPropertyName = "id";
btnColumn.Width = 100;
btnColumn.ReadOnly = true;
this.dataGridView1.Columns.Add(btnColumn);
this.dataGridView1.DataSource = dt;
foreach (DataGridViewRow dr in this.dataGridView1.Rows)
{
if (dr.Cells[0].Value != null)
{
int i;
if ((int.TryParse(dr.Cells[0].Value.ToString(),out i)))
{
if (i % 2 == 0)
{
DataGridViewTextBoxCell txtcell = new DataGridViewTextBoxCell();
dr.Cells[0] = txtcell;
}
}
}
}
}
}