Hello,
In datagridview, how do I create rows and columns programmatically? I'm trying to create a Spreadsheet.
column a - z
row 1 - 50
Thank you.
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.AllowUserToAddRows = true;
DataTable dt = new DataTable();
DataRow dr = null;
char letter='a';
while(letter<='z'){
dt.Columns.Add(new DataColumn(letter.ToString(), typeof(string)));
letter++;
}
for (int i = 1; i <= 50; i++) {
dr = dt.NewRow();
dt.Rows.Add(dr);
}
//Bind the Gridview
dataGridView1.DataSource = dt;
for (int i = 1; i <= 50; i++)
{
this.dataGridView1.Rows[i - 1].HeaderCell.Value = (i).ToString();
}
}
Comments
Leave a comment