Click here to Skip to main content
11,495,049 members (54,049 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C#
note it is windows application.

Holiday Reason(table Name Leave)

20/2/2013 Labour Day
25/2/2013 Holiday

When i select the calendar that month all dates will display in datagridview using csharp.

And also user did not able to select the sunday date in that month.

for the above two condition i written a code as follows;
DateTime dt1 = Faculty_Available_Calendar.SelectionStart;
dt1 = new DateTime(dt1.Year, dt1.Month, 1);
DateTime dt2 = dt1.AddMonths(1);
int numDays = (dt2 - dt1).Days;
if (DGVCalendar.RowCount < numDays)
   DGVCalendar.RowCount = numDays;
int row = 0;
while (dt1 < dt2)
   DGVCalendar.Rows[row].Cells[1].Value = dt1.ToString("dd-MMM-yyyy");
   DGVCalendar.Rows[row].Cells[0].Value = true;  //All checkbox Checked Defaulty 

   if (dt1.DayOfWeek == DayOfWeek.Sunday)
      DGVCalendar.Rows[row].ReadOnly = true;
      DGVCalendar.Rows[row].Cells[0].Value = false;
      DGVCalendar.Rows[row].Cells[0].Style.BackColor = Color.Orange;
      DGVCalendar.Rows[row].Cells[1].Style.BackColor = Color.Orange;
      DGVCalendar.Rows[row].Cells[2].Style.BackColor = Color.Orange;
      DGVCalendar.Rows[row].Cells[2].Value = "Sunday";
   dt1 = dt1.AddDays(1);
I want to check another condition selected date in datagridview is present in another Table.

if user select the 20/2/2013 (the above date in datagridview) using checkbox user select the 20/2/2013 Date shows the message "select date is not allowed"

Because that date is in Leave Table.

for that how to validate.

please help me.

How can i do,please help me,how can i do,tell me the answer.

Narasiman P.

note it is windows application.
Posted 22-Feb-13 21:19pm
Edited 23-Feb-13 6:07am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

hi professional
there is many way to do this task may some one told you smart way or some one not that way but over all as per my logic for this you have two task...

1. when user select the date of 1st table then you have to take that date in a variable(sql query).

2. and in 2nd and main task then using sql select with where='"+your variable+"' conditon query you have to read that day in secound table and if get HasRow= true or datareader make true...then you have to finally pop up your massege that "Date Not Allowed"..

Are you getting na that what actually i want to share with you....have any doubt plz comment below or want logic from my end then also...but 1st try from your end...

Happy to help

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

  Print Answers RSS
0 Dnyaneshwar@Pune 692
1 Sergey Alexandrovich Kryukov 350
2 CHill60 318
3 Sascha Lefèvre 280
4 Nakul Chaudhari 236
0 Sergey Alexandrovich Kryukov 10,297
1 OriginalGriff 8,821
2 Sascha Lefèvre 3,864
3 Maciej Los 3,412
4 Richard Deeming 2,500

Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 23 Feb 2013
Copyright © CodeProject, 1999-2015
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