Property not available when inheriting DateTimePicker Control

5 posts, 0 answers
  1. Priyam
    Priyam avatar
    6 posts
    Member since:
    Dec 2012

    Posted 04 Dec 2013 Link to this post

    I have inherited DateTimePicker control in a custom UserControl but now the usercontrol does not have some properties like Value, Format, etc. How do I override / access these properties in my main form when I use these usercontrols?
  2. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 06 Dec 2013 Link to this post

    Hello Priyam,

    Thank you for writing.

    I am not quite sure what do you mean by "I have inherited DateTimePicker control in a custom UserControl". Perhaps, you have added RadDateTimePicker to a UserControl, if so and you cannot access the RadDateTimePicker from a Form hosting the UserControl, then you just need to add a property to the UserControl, which returns the RadDateTimePicker control, or just change its Modifier to Public.

    If this is not the case, please provide more details about the precise scenario and I will gladly assist you with it.

    Regards,
    Stefan
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Ke
    Ke avatar
    18 posts
    Member since:
    Feb 2016

    Posted 08 Mar in reply to Stefan Link to this post

    Hi Stefan, 

    I have came across the same problem. How do I add a property to the UserControl, so that it returns the base radcontrol property? Can you show me one example, please? thank you!

  5. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 10 Mar Link to this post

    Hello Ke,

    Thank you for writing.

    If I understand your scenario correctly, you have a UserControl that contains a specific RadControl. Then, the UserControl is added to the Form and you need to access the RadControl's properties from the Form. In order to achieve it, you can follow the explained approach in Stefan's post: "you just need to add a property to the UserControl, which returns the RadDateTimePicker control". Thus, you will be able to access the RadDateTimePicker from the Form. Here is demonstrated a sample code snippet:
    public partial class UserControl1 : UserControl
    {
        public UserControl1()
        {
            InitializeComponent();
        }
     
        public RadDateTimePicker DateTimePicker
        {
            get
            {
                return this.radDateTimePicker1;
            }
        }
    }

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
     
            this.userControl11.DateTimePicker.Value = new DateTime(2016, 1, 1);
        }
    }

    If it is not suitable to your case, it would be greatly appreciated if you can provide more details about the precise case and the exact goal that you are trying to achieve. Thus, we would be able to think about a suitable solution and assist you further. Thank you.

    I hope this information helps. Should you have further questions I would be glad to help.
     
    Regards,
    Dess
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  6. Ke
    Ke avatar
    18 posts
    Member since:
    Feb 2016

    Posted 10 Mar in reply to Dess Link to this post

    Thank you for your examples. They are great to understand. 

    I did exactly the same thing to change the backcolor of dropdownlist. And last night I realized that both my ways of changing accessibility to visual elements are correct. Thank you again for your examples to confirm.  

Back to Top
UI for WinForms is Visual Studio 2017 Ready