Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Note: It is a windows applciation

i have one datetimepicker.when i select the month that month date will be displayed in dategridview.


Ouptut as follows in datagridview;


when i select the datetimepicker that month date will be displayed in datagridview.

for example i choose, March in datetime picker means in datagridview output as follows;


Datgridview


March
1/1/2013
2/1/2013
3/1/2013
4/1/2013
5/1/2013
6/1/2013
7/1/2013
8/1/2013
9/1/2013
10/1/2013
11/1/2013
12/1/2013
13/1/2013
15/1/2013
16/1/2013
17/1/2013
18/1/2013
19/1/2013
20/1/2013
21/1/2013
22/1/2013
23/1/2013
24/1/2013
25/1/2013
26/1/2013
27/1/2013
28/1/2013
29/1/2013
30/1/2013
31/1/2013
Posted
Comments
OriginalGriff 17-Feb-13 7:22am    
And?
You seem to have forgotten to tell us what your problem is...

From what I understand you want to fill the datagrid in the list of days per month.
You can use the static method DaysInMonth(int year, int month) in the DateTime class to get the number of days the requested month has.
From there you can build a collection of strings (or whatever).
For example:

C#
int daysInMonth = DateTime.DaysInMonth(2013, 2);
string[] daysCollection = new string[daysInMonth];
for (int index = 0; index < daysInMonth; index++)
{
    daysCollection[index] = (index + 1).ToString() + "/2/2013";
}



Now you can fill your datagrid data source with the collection you just created
 
Share this answer
 
Comments
[no name] 17-Feb-13 8:24am    
i dont want to use static method.

here when i choose any one month in datetimepicker that month date to be displayed in datagridview using csharp.

Note:it is windows application.
Shahare 17-Feb-13 9:07am    
The static method is the DateTime.DaysInMonth(int, int) method which you can find in the DateTime class. Nothing I would recommend you to write :)

The code above can be placed inside the datetimepicker selection changed event and the daysCollection is the collection you need to set for the datagrid datasource:

datagrid1.DataSource = daysCollection;
If u need only to retrieve date from DateTimePicker then u can use the code
DateTime date = DateTimePicker.Value.Date;

if u need only month then u can use
DateTime month  = DateTimePicketr.Value.Month;
 
Share this answer
 

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