Adding new columns to a Winforms DataGridView via code

前端 未结 4 2407
情歌与酒
情歌与酒 2021-02-19 05:43

I\'m trying to add N number of columns for each days of a given month:

var daysCount = DateTime.DaysInMonth(DateTime.Now.Year, month);

for (int i = 1; i <= d         


        
4条回答
  •  时光取名叫无心
    2021-02-19 06:28

    set your table and add needed columns. then use:

    var daysCount = DateTime.DaysInMonth(DateTime.Now.Year, 1);
    
    for (int i = 0; i <= daysCount; i++)
            {
              i = dataGridView1.Rows.Add(new DataGridViewRow());
    
    
                            dataGridView1.Rows[i].Cells["YourNameCell"].Value = i.ToString();
    
           }
    

    Frist row is 0, not 1. probabily your error are these.

提交回复
热议问题