Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I use the winforms dateTimepicker control and I am looking for how to disable the insert date in a database. when using it add a new product with their date it will disable in the following insert?

What I have tried:

i try with this code but it 's not worked

C#
List<datetime> bold = new List<datetime>();
for (int i = 0; i < 3; i++)
    bold.Add(DateTime.Now.AddDays(i*3).Date);

monthCalendar1.BoldedDates = bold.ToArray();


C#
List<datetime> selected = new List<datetime>();

private void monthCalendar1_DateSelected(object sender, DateRangeEventArgs e)
{
    for   (DateTime dt = monthCalendar1.SelectionStart.Date; 
                    dt.Date <= monthCalendar1.SelectionEnd.Date; 
                    dt = dt.AddDays(1))
    {
        if (!monthCalendar1.BoldedDates.Contains(dt)
        && !selected.Contains(dt)) selected.Add(dt.Date);
    }
}
Posted
Updated 5-Dec-16 17:27pm
Comments
dan!sh 5-Dec-16 6:38am    
I am not sure I get this. Are you saying that you want to allow user to select date when they are inserting a new product? And then disable it?
abboudi_ammar 5-Dec-16 13:41pm    
yes exactly, this what i want. i want to allow user to select the date which not inserted in the datebase.and i want to disable the date which reserved (existed in the database).all of this i want to show that via the control "DateTimePicker" in winform

1 solution

Judging by comment, you want to disable the certain dates if they exist in database.

There is no built in or standard way to do it. You can either handle ValueChanged event and if the date exists in database, show a MessageBox with message to choose another date.

Another option is to go for any third party control or write your own.
 
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