如何从datagridview中的两个datetimepickers之间的差异中显示月份列表? [英] How to display the list of months from the difference between two datetimepickers inside a datagridview?

查看:82
本文介绍了如何从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...

推荐答案

一种方法可能是从元组数据创建一个字符串列表,然后做你通常做的任何事情,用List填充DataGridView中的一列:
One way might to create a List of Strings from the Tuple data, and then do whatever you usually do to fill a column in a DataGridView with the List:
// 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"
>


看起来您需要的不仅仅是一些常规帮助。我会使用与每个月对应的数字,并将其翻译成您所做的功能。这将有助于我们看到所有帮助者想要知道的两个问题:首先,您需要将这些问题作为数据类型/形式出现,其次,您希望将其放在哪里(例如,选择框,gridview或什么)。您要前往哪个控件有助于确定您需要输出的形式。
It looks like you need a bit more than just some general help. I would use the number that corresponds to each month and get it translated in a function you make. This will help us to see two questions that all of your helpers want to know: first, what data types/form are you needing this to come out as, second, where do you want to put it (e.g. Selection box, gridview, or what). Which control you are heading to helps decide what form you need your output.


这篇关于如何从datagridview中的两个datetimepickers之间的差异中显示月份列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆