Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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));

           }



       }


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...
Posted
Updated 18-Jan-15 15:35pm
v2
Comments
BillWoodruff 18-Jan-15 21:18pm    
You might want to wait a bit before posting a new question while your first question is still being responded to.

And, for this question, it's very important for you to state clearly how you want to "display" the results. You tell us where you will display the results ... a DataGridView ... but, display as WHAT : as strings ? ... or ... ?
DarkDreamer08 18-Jan-15 21:38pm    
I updated now the question. I am sorry of asking such question in a quick due to time is running out of me. I need to make this because I consumed a lot of time to fix some of the major module for my system. Hope you guys understand. Thank you once again.
DamithSL 18-Jan-15 22:04pm    
in which control you want to show the months?
DarkDreamer08 18-Jan-15 22:25pm    
after being pressed button1, it will read the above codes that shows the months that came from the difference between the two date time picker and those months will be displayed in the datagridview. Hope you get it :)

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:
C#
// 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"
>
 
Share this answer
 
Comments
DarkDreamer08 19-Jan-15 0:04am    
Where should I put it? inside the button 1? sorry, a little bit confused about that.
DarkDreamer08 19-Jan-15 0:29am    
How to fill it to the datagridview
BillWoodruff 19-Jan-15 2:42am    
You need to study how to structure a DataGridView and fill rows, and columns. MSDN has good basic tutorials on how to do that. Most likely you will want to create a pre-defined DataSet template with appropriate row and column definitions; then, when you have filled the DataSet with data, you will bind the DataGridView to the DataSet.

See:

http://cplus.about.com/od/learnc/ss/adv_winforms_5.htm
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.
 
Share this answer
 
Comments
DarkDreamer08 18-Jan-15 22:31pm    
I have already updated my question above a 50 minutes ago. I said that the data types of those months will be strings and will be displayed inside the datagridview after being pressed the button1. Do I lack of something? If I, please tell me. :laugh: .I somehow cannot understand your first statement on your comment. Sorry for that. -_-

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900