datetimepicker problem

csharp Malawi
  • 13 years ago

    Hi all,

    I got a problem in a datetimepicker. What i need to do is whenever i select a particular date in datetimepicker, the corresponding day of that date has to be checked in the checkboxes that are present besides to it. I have 7 checkboxes with text Monday to Sunday. So, whatever the day is choosen that checkbox has to be checked. Can anyone pls help me in what to do and how to do.

    For example the date i have choosen is 21/02/2008 which is Thursday, so checkbox having Thursday to be checked automatically.

    Thanks in advance..

  • 13 years ago

     Hi Priya,

    You can do it in a simple way.
    Make a method like this.

     private void UnCheckedControl()
            {
                checkBox1.Checked = false;
                checkBox2.Checked = false;
                checkBox3.Checked = false;
                checkBox4.Checked = false;
                checkBox5.Checked = false;
                checkBox6.Checked = false;
                checkBox7.Checked = false;
            }

    place following code under your dateTimePicker1_ValueChanged event and run the application. Hope this will solve your issue. There are other complex ways to solve this issue.

     DateTime dt = dateTimePicker1.Value;
                if (dt.DayOfWeek.ToString() == "Monday")
                {
                    UnCheckedControl();
                    checkBox1.Checked= true;
                }
                else if (dt.DayOfWeek.ToString() == "Tuesday")
                {
                    UnCheckedControl();
                    checkBox2.Checked = true;
                }
                else if (dt.DayOfWeek.ToString() == "Wednesday")
                {
                    UnCheckedControl();
                    checkBox3.Checked = true;
                }
                else if (dt.DayOfWeek.ToString() == "Thursday")
                {
                    UnCheckedControl();
                    checkBox4.Checked = true;
                }
                else if (dt.DayOfWeek.ToString() == "Friday")
                {
                    UnCheckedControl();
                    checkBox5.Checked = true;
                }
                else if (dt.DayOfWeek.ToString() == "Saturday")
                {
                    UnCheckedControl();
                    checkBox6.Checked = true;
                }
                else if (dt.DayOfWeek.ToString() == "Sunday")
                {
                    UnCheckedControl();
                    checkBox7.Checked = true;
                }

  • 13 years ago

    Thank you, it worked well

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“If debugging is the process of removing software bugs, then programming must be the process of putting them in.” - Edsger Dijkstra