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 7643085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:21:27+00:00 2026-05-31T09:21:27+00:00

I am trying to use an extension method to initialize a datetimepicker control to

  • 0

I am trying to use an extension method to initialize a datetimepicker control to being on the previous work day from today. However this is causing my form design window to show an error as it cannot find the extension method.

You can quickly replicate this error by creting a new windows form, adding a datetimepicker. Then create the following new class to extend DateTime to add a NextDay() method:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ExtensionMethodDesignWindowTest
{
    public static class DateTimeExtensions
    {
        public static DateTime NextDay(this DateTime date)
        {
            return date.AddDays(1);
        }
    }
}

And finally in Form1.designer.cs add the line

this.dateTimePicker1.Value = DateTime.Today.NextDay();

under the datetimepicker1 section.
(edit: and also using.system; at the top)

When you navigate back to the form design window you should see the error. Note that this code builds fine and runs correctly, with the datetimepicker showing tomorrow’s date when the form loads. Also if you replace the added line in Form1.designer.cs with

this.dateTimePicker1.Value = DateTime.Today.AddDays(1);

Then you do not get the error in the design window. This makes me assume that the error is because the windows form design window can’t see the ExtensionMethodDesignWindowTest namespace.

How can I make the form design window be able to see my extension methods?

Thanks
Dan

btw though I doubt it matters here is some IDE version info for what I’m using:
Microsoft Visual Studio 2010
Version 10.0.30319.1 RTMRel
Microsoft .NET Framework
Version 4.0.30319 RTMRel

  • 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-05-31T09:21:29+00:00Added an answer on May 31, 2026 at 9:21 am

    Generally it’s bad practice to put your own code in the designer – VS may regenerate the designer code and then you’d lose your changes.

    You should be able to invoke your extension method from eg Form_Load ie

    this.dateTimePicker1.Value = DateTime.Today.NextDay();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use this UrlHelper extension method: public static string ToPublicUrl(this UrlHelper
I'm hacking around in a Firefox extension, trying to use E4X. However, I've come
Trying to use this method (gist of which is use self.method_name in the FunnyHelper
I'm trying to write an extension method that I can use to copy values
I am trying to do use .Select extension method on ListView.SelectedItems which is SelectedListViewItemCollection
I am trying to implement a extension method to initialize my Moq repositories for
I have an extension method on HttpRequest that I'm trying to use inline on
I am trying to use the Join(...) extension method to build a query based
I'm trying to use the Html.DropDownList extension method but can't figure out how to
I was trying Include extension method from http://damieng.com/blog/2010/05/21/include-for-linq-to-sql-and-maybe-other-providers , but it does not really

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.