Reputation: 1
can any one Tell me how can i create columns in datagridview so that when i select month number 1,3,5,7,8,10,12 (jan, march, may, july, august, oct, december) then 31 columns should be create in datagridview because these months have 31 days when i select month number 4,6,9,11 (April, jun, september, november)then 30 columns should be create automatically in datagridview and when i select month number 2 (feb) then then show 28 column in datagridview. month will be selected from "Date time picker" This is employ attendance for created in vb.net I upload screen shoot for more explation.
Upvotes: 0
Views: 1564
Reputation: 2164
Try something like this on the DateTimePicker ValueChanged event:
DataGridView1.Columns.Clear()
For i As Integer = 1 To DateTime.DaysInMonth(DateTimePicker1.Value.Year, DateTimePicker1.Value.Month)
DataGridView1.Columns.Add(i.ToString, i.ToString)
Next
DaysInMonth
is a static function of the DateTime class that returns the number of days of the month and year you pass as parameters. This code just iterates from 1 to the value this function returns and adds one column for each day to the DataGridView.
Upvotes: 1