本文介绍了如何从datagridview中的两个datetimepickers之间的差异中显示月份列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我想知道如何在点击datagridview里面的按钮后显示月份列表。
以下是我从这里获得帮助的代码。
Hi guys,
I would like to know if how am I able to display the list of months after being clicked the button inside the datagridview.
Below is the Code that I got helped also from here.
private DateTimeFormatInfo dateTimeFormat = CultureInfo.CurrentCulture.DateTimeFormat;
private List<Tuple<string, int>> BetweenMonths = new List<Tuple<string, int>>();
private void button1_Click_1(object sender, EventArgs e)
{
DateTime startDate = dateTimePicker1.Value;
DateTime endDate = dateTimePicker2.Value;
if (endDate < startDate)
{
DateTime temp = endDate;
endDate = startDate;
startDate = temp;
}
BetweenMonths.Clear();
for (DateTime date = startDate; date < endDate; date = date.AddMonths(1))
{
BetweenMonths.Add(Tuple.Create(dateTimeFormat.GetMonthName(date.Month), date.Year));
}
}
我想在datagridview中显示月份列表,如下所示:
月
2015年1月
2015年2月
2015年3月
2015年4月
等等...
I want to display the list of months in the datagridview as strings like this:
Month
January 2015
February 2015
March 2015
April 2015
and So on...
推荐答案
// example
List<string> MonthData = BetweenMonths.Select(itm => itm.Item1 + ", " + itm.Item2).ToList();
// sample output
> ? MonthData
Count = 5
[0]: "September, 2014"
[1]: "October, 2014"
[2]: "November, 2014"
[3]: "December, 2014"
[4]: "January, 2015"
>
这篇关于如何从datagridview中的两个datetimepickers之间的差异中显示月份列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!