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 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.
dataGridView1.Columns.Add("Column","Jan");
– Spacemangrid1.Columns.Add
method to do it – V4Vendettadatagridview
bound to some datasource ? – yogi