Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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 17-Feb-13 2:20am
Comments
OriginalGriff at 17-Feb-13 7:22am
   
And?
You seem to have forgotten to tell us what your problem is...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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:
 
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
  Permalink  
Comments
Member 8054539 at 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 at 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;
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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;
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 390
1 Jochen Arndt 165
2 Richard MacCutchan 135
3 DamithSL 95
4 Garth J Lancaster 90
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,260


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 17 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100