473,326 Members | 2,113 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,326 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 6532
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.