473,394 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

REPOST: Displaying and Editing a Time value in a PropertyGrid

When using a PropertyGrid, I have an object with a Date property, but I am
only interested in the Time portion. How do I make the PropertyGrid allow
editing the time only? Just the hours and minutes, preferably?

Thanks

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Nov 22 '05 #1
4 6542
You can create a TypeConverter for the value. Basically the type converter's
job is to convert some value to a string and enable a similar string to be
parsed back to some meaningful value.

Shawn Burke's introduction to creating designable controls in MSDN is a
great example.

The code below my signature shows a similar type-converter. Any DateTime
property can be made to use this type converter using the
TypeConverterAttribute.

--
Bob Powell [MVP]
Visual C#, System.Drawing

The Image Transition Library wraps up and LED style instrumentation is
available in the June of Well Formed for C# or VB programmers
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml

----------------------------------------------------------------------------
---------------------------------

/// <summary>

/// Summary description for TimeConverter.

/// </summary>

public class TimeConverter : TypeConverter

{

public TimeConverter()

{

}

public override bool
CanConvertFrom(System.ComponentModel.ITypeDescript orContext context,
System.Type sourceType)

{

if(sourceType == typeof(string))

return true; //yes we can convert from a string

return base.CanConvertFrom(context, sourceType);

}

/// <summary>

/// finds out whether or not the type of data passed in is convertable to a
string

/// </summary>

/// <param name="context"></param>

/// <param name="culture"></param>

/// <param name="value"></param>

/// <returns></returns>

public override object
ConvertFrom(System.ComponentModel.ITypeDescriptorC ontext context,
System.Globalization.CultureInfo culture, object value)

{

if(value is string)

{

DateTime ds = DateTime.ParseExact((string)value,new
string[]{"T"},culture,DateTimeStyles.AllowWhiteSpaces);

return ds;

}

return base.ConvertFrom(context, culture, value);

}

/// <summary>

/// finding out the form the data is going to be converted to

/// </summary>

/// <param name="context"></param>

/// <param name="destinationType"></param>

/// <returns></returns>

public override bool
CanConvertTo(System.ComponentModel.ITypeDescriptor Context context,
System.Type destinationType)

{

if(destinationType == typeof(DateTime))

return true;

return base.CanConvertTo(context, destinationType);

}

public override object
ConvertTo(System.ComponentModel.ITypeDescriptorCon text context,
System.Globalization.CultureInfo culture, object value, System.Type
destinationType)

{

if(destinationType==typeof(string))

{

return ((DateTime)value).ToLongTimeString();

}

return base.ConvertTo(context,culture,value,destinationTy pe);

}

/// <summary>

/// checking the validity of the input data and if its valid converting it
to its destination type

/// this is then returned

/// </summary>

/// <param name="context"></param>

/// <param name="value"></param>

/// <returns></returns>

public override bool IsValid(System.ComponentModel.ITypeDescriptorConte xt
context, object value)

{

if(value is string)

{

try

{

DateTime ds = DateTime.ParseExact((string)value,new
string[]{"T"},CultureInfo.CurrentCulture,DateTimeStyles.Al lowWhiteSpaces);

return true;

}

catch(Exception)

{

return false;

}

}

return false;

}
}
----------------------------------------------------------------------------
---------------------------------


"Chris Dunaway" <"dunawayc[[at]_lunchmeat_sbcglobal[dot]]net"> wrote in
message news:nj****************************@40tude.net...
When using a PropertyGrid, I have an object with a Date property, but I am
only interested in the Time portion. How do I make the PropertyGrid allow
editing the time only? Just the hours and minutes, preferably?

Thanks

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.

Nov 22 '05 #2
On Tue, 10 Aug 2004 22:06:44 +0200, Bob Powell [MVP] wrote:
The code below my signature shows a similar type-converter. Any DateTime
property can be made to use this type converter using the
TypeConverterAttribute.


Thanks for the code and I'll definitely look into that. But I guess my
question is regarding the control used by the PropertyGrid to handle
editing the value. Right now, with a date property, if I click the drop
down arrow, it displays a calendar control to pick a date.

What I would like is a up down control like the DateTimePicker control
exposes to allow the user to edit the time.

Thanks again

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Nov 22 '05 #3
It's also possible to replace the editor with a custom one. The UITypeEditor
enables you to create a graphical editor which integrates with the
PropertyGrid. There are several examples of that in MSDN also. Sorry but I
don't have code for a clock editor.

--
Bob Powell [MVP]
Visual C#, System.Drawing

The Image Transition Library wraps up and LED style instrumentation is
available in the June of Well Formed for C# or VB programmers
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml


"Chris Dunaway" <"dunawayc[[at]_lunchmeat_sbcglobal[dot]]net"> wrote in
message news:1w*******************************@40tude.net. ..
On Tue, 10 Aug 2004 22:06:44 +0200, Bob Powell [MVP] wrote:
The code below my signature shows a similar type-converter. Any DateTime
property can be made to use this type converter using the
TypeConverterAttribute.


Thanks for the code and I'll definitely look into that. But I guess my
question is regarding the control used by the PropertyGrid to handle
editing the value. Right now, with a date property, if I click the drop
down arrow, it displays a calendar control to pick a date.

What I would like is a up down control like the DateTimePicker control
exposes to allow the user to edit the time.

Thanks again

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.

Nov 22 '05 #4
On Wed, 11 Aug 2004 09:06:39 +0200, Bob Powell [MVP] wrote:
It's also possible to replace the editor with a custom one. The UITypeEditor


Thanks Bob, I'll check that out.

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Nov 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Chris Dunaway | last post by:
When using a PropertyGrid, I have an object with a Date property, but I am only interested in the Time portion. How do I make the PropertyGrid allow editing the time only? Just the hours and...
3
by: Diego TERCERO | last post by:
Hi... I'm working on a tool for editing text resources for a family of software product my company produces. These text resources are found in a SQL Server database, in a table called...
0
by: m. pollack | last post by:
<I've reposted this as it was slipping away over the horizon Hi all, I've been writing an application that uses a class object (call it Element) that I need to expose to the user at runtime for...
2
by: Dino M. Buljubasic | last post by:
I have several context menus added to my form. The form is displaying items in listviews connected to the context menus. When I click on an item in a list view, a popup context menu shows allowing...
0
by: ljlevend | last post by:
I want to change which properties of a class are visible in a PropertyGrid at run-time. I know that the System.ComponentModel.Browsable attribute allows you to specify the visibility of properties...
4
by: ljlevend | last post by:
Is there any way to prevent a PropertyGrid from allowing the user to expand the elements of an array? For properties that are of type ArrayList or CollectionBase a PropertyGrid only allows the...
0
by: movieknight | last post by:
Hi, I have a class which I am feeding to the propertygrid, and I am exposing a Mesh object from my class for the propertygrid to display. I want the propertygrid to show the values (when you...
4
by: Peted | last post by:
Hi i am trying to make a small mdoification to and exisiting dll control, in its source code. Im trying to expose one of its internal properties so the user can set it in the ide at...
4
by: =?Utf-8?B?SHVnaA==?= | last post by:
Hi there I have a Propertygrid in a C# project that has a number of IP addresses displayed. What I would like to do is to a) Edit them in-place as the 4 octets, ie edit them as xxx.xxx.xxx.xxx...
2
by: John Hewitt | last post by:
I am currently able to change a PropertyGrid to select a particular GridItem by iterating through the current selected GridItem parent.GridItem's However, This selects and focuses on the Label of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.