I'd suggest to use
DataTable[
^] object as a
DataSource[
^] of
dataGridView4
, because this component enables you to manage data in easy way:
DataTable dt = new DataTable();
DateTime startdate = new DateTime(2019,1,1);
DateTime enddate = startdate.AddMonths(1).AddDays(-1);
TimeSpan ts = (TimeSpan)(enddate-startdate);
int dayscount = (int)ts.TotalDays;
CultureInfo ci = new CultureInfo("en-US");
for(int i=0; i<dayscount; i++)
{
dt.Columns.Add(new DataColumn(startdate.AddDays(i).ToString("yyyy-MM-dd"), typeof(string)));
}
dataGridView4.AutoGenerateColumns = true;
dataGridView4.DataSource = dt;
Using above code, you'll get columns like this:
2019-01-01 2019-01-02 ... 2019-01-30 2019-01-31
For further details, please see:
How to: Bind data to the Windows Forms DataGridView control | Microsoft Docs[
^]
Object.ToString Method (System) | Microsoft Docs[
^]