Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Mask for DateTime field in PropertyGrid
 

Mask for DateTime field in PropertyGrid

Hi all,

I am using C#, .NET and I regularly use PropertyGrid control in my project. Ifound difficulty in creating and applying a datemask(dd/mm/yyyy) to the DateTime property item in the propertygrid such a way that, user can enter only in that format. For example, by default "dd/mm/yyyy" should be displayed in the DateTime property field. When user key in numbers, the numbers should replace the respective places in the field dynamically. Ofcourse, user can give input from DateTime picker also.

Please, suggest me withcode snippets or sample source code. Thanks in advance.
Let me know if further information is needed.

Regards,
Kumar
Kumar...  Wednesday, February 18, 2009 1:28 PM
Hi,

Base on my understanding, you want to custom date format for DataTimePicker. You can try it like this:

DateTimePickerFormat.Custom;

"dd/MM/yyyy";

Custom Date and Time Format Strings

If I misunderstood you, or you have other questions, please feelfree to tell me.

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Friday, February 20, 2009 9:06 AM

Hi Ling

Thank you for your response. As you know, in general, there are two ways of giving input values to a property item which is of type DateTime.

1) UsingDateTimePicker
2) Entering numbers using keyboard

Here, I am talking about using keyboard. By default, format (e.g., mm/dd/yyyy ) should be displayed in the property item field. When user wants to key in values using keyboard in the DateTime property field in the propertygrid, each key in number should replace the respective letter of the mask at current selection. For example, if user enters 6 at 2nd position of the month part, m6/dd/yyyyy should be displayed in the field and separators and other letters should remain same in position even user deletes them.

Please, suggest me in the same.

Another question:

For suppose, there are 4 propertygrids and3 list boxes have been placed on a main Form in my solution. How can I get information of the currently active/selected controlwhen the project isrunning and how canI access that control in the code? Please, advise me.

Regards,

Kumar

Kumar...  Friday, February 20, 2009 12:19 PM
Hi,

Do you mean you want to display the string “mm/dd/yyyy�in the dateTimePicker?

If we set the customFormat follow my last reply, this will restrict dateTimePicker only accept the digit. So we can’t add the string to the dateTimePicker follow this way.

You can use this.ActiveControl to get the current control.

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Tuesday, February 24, 2009 4:13 AM
We are changing the issue type to “General Discussion�because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to “Question�by opening the Options list at the top of the post window, and changing the type. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.
Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Friday, February 27, 2009 1:23 PM

You can use google to search for other answers

Custom Search

More Threads

• how to set default enter & escape button of a Form in vb.net?
• UserControl Modifiers Property Default Value ???
• Reg: Custom Drawing the Menu in Dotnet 2.0
• Authenticating users in windows application...?
• listBox or listView: 1 item=Multiple rows with formatting
• show fomr in a Tab page
• Panel control
• Smart tags on my control causing VS2005 to crash.
• Windows Forms
• how to host different controls in the same column in DataGridView control