0
votes

I have two datetime variables Start Date and End Date.Suppose Start Date is 01-Jan-2013 and End date is 01-Mar-2013.Then I have to add datagridview columns as Jan,Feb,Mar. Please help me in achieving this.

1
how do u try?? I mean u should show some codesAtish Dipongkor
What have you tried? What about a simple dataGridView1.Columns.Add("Column","Jan");Spaceman
Well you can use grid1.Columns.Add method to do itV4Vendetta
Is your datagridview bound to some datasource ?yogi
add column permanently or temporary ?matzone

1 Answers

1
votes

Try this

string[] months = new string[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };

DateTime startDate = new DateTime(2013, 1, 1);
DateTime endDate = new DateTime(2013, 3, 1);

while (true)
{
   dataGridView1.Columns.Add(months[startDate.Month - 1], months[startDate.Month - 1]);
   startDate = startDate.AddMonths(1);
   if (startDate > endDate)
       break;
}

Of course you should make proper validation checks in this code too.