Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7944707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:37:58+00:00 2026-06-04T00:37:58+00:00

I came up with this code, which I thought was rather clever (the requirement

  • 0

I came up with this code, which I thought was rather clever (the requirement is that if the selected date is in the past, the TextBoxes should be readonly, otherwise (today’s date or a future date) they should be editable):

bool? setReadOnly = null;

if (SelectedDateIsInThePast() && (!currentlyReadOnly)) {
    setReadOnly = true;
} else if (!SelectedDateIsInThePast() && (currentlyReadOnly)) {
    setReadOnly = false;
}
if (setReadOnlyToTrue.HasValue) {
    foreach (Control ctrl in tableLayoutPanelPlatypus.Controls) {
        if (ctrl is TextBox) {
            tb = (TextBox)ctrl;
            tb.ReadOnly = setReadOnlyToTrue.Value;
        }
    }
}

…but find that nullable bools are “data type non grata” among my compadres.

Is there a non-complicated way to do the same thing (only loop through the controls if the readonly value needs to be changed?). Of course, I could simply set them regardless of whether they needed to be set this way:

if (SelectedDateIsInThePast()) {
    setReadOnly = true;
} else {
    setReadOnly = false;
}
foreach (Control ctrl in tableLayoutPanelPlatypus.Controls) {
    if (ctrl is TextBox) {
        tb = (TextBox)ctrl;
        tb.ReadOnly = setReadOnly;
    }
}

…but I don’t like to perform moot operations, if it’s reasonably possible to avoid them.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T00:38:00+00:00Added an answer on June 4, 2026 at 12:38 am

    Factor the loop into a method, and only call the method in the cases you set setReadOnly:

    if (SelectedDateIsInThePast() && (!currentlyReadOnly)) {
        SetReadOnly(true);
    } else if (!SelectedDateIsInThePast() && (currentlyReadOnly)) {
        SetReadOnly(false);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I came across this code on reddit . I would have thought that type
I recently came along this line of code: CustomData_em_free_block(&em->vdata, &eve->data); And I thought, isn't:
I just came a cross this nice code that makes this scatter matrix plot:
Well I was reading this post and then I came across a code which
in the book i'm learning from i came across this code snippit: while (i
Today I came across this question: you have a code static int counter =
i came across this problem, my code in the viewWillAppear method is not executed
So I'm going through old code (2.0) and I came across this: object isReviewingValue
Whilst working on some generally horrible Javascript code this morning, I came across the
The other day, I came across this construct: static_cast<size_type>(-1) in some example C++ code,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.