473,548 Members | 2,721 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_lunch meat_[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 6560
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
TypeConverterAt tribute.

--
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.Componen tModel.ITypeDes criptorContext context,
System.Type sourceType)

{

if(sourceType == typeof(string))

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

return base.CanConvert From(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(Sys tem.ComponentMo del.ITypeDescri ptorContext context,
System.Globaliz ation.CultureIn fo culture, object value)

{

if(value is string)

{

DateTime ds = DateTime.ParseE xact((string)va lue,new
string[]{"T"},culture,D ateTimeStyles.A llowWhiteSpaces );

return ds;

}

return base.ConvertFro m(context, culture, value);

}

/// <summary>

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

/// </summary>

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

/// <param name="destinati onType"></param>

/// <returns></returns>

public override bool
CanConvertTo(Sy stem.ComponentM odel.ITypeDescr iptorContext context,
System.Type destinationType )

{

if(destinationT ype == typeof(DateTime ))

return true;

return base.CanConvert To(context, destinationType );

}

public override object
ConvertTo(Syste m.ComponentMode l.ITypeDescript orContext context,
System.Globaliz ation.CultureIn fo culture, object value, System.Type
destinationType )

{

if(destinationT ype==typeof(str ing))

{

return ((DateTime)valu e).ToLongTimeSt ring();

}

return base.ConvertTo( context,culture ,value,destinat ionType);

}

/// <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. ITypeDescriptor Context
context, object value)

{

if(value is string)

{

try

{

DateTime ds = DateTime.ParseE xact((string)va lue,new
string[]{"T"},CultureIn fo.CurrentCultu re,DateTimeStyl es.AllowWhiteSp aces);

return true;

}

catch(Exception )

{

return false;

}

}

return false;

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


"Chris Dunaway" <"dunawayc[[at]_lunchmeat_sbcg lobal[dot]]net"> wrote in
message news:nj******** *************** *****@40tude.ne t...
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_lunch meat_[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
TypeConverterAt tribute.


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_lunch meat_[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_sbcg lobal[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
TypeConverterAt tribute.


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_lunch meat_[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_lunch meat_[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
524
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 minutes, preferably? Thanks -- Chris dunawaycsbcglobal_lunchmeat_net
3
2531
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 "Resource" with the following structure : Resource{,en,fr,es} Yes.. these are the only languages supported actually. A couple of rows in that table would...
0
1210
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 editing. To do this, I've been using the PropertyGrid control. The Element object has a collection property that contains references to other...
2
1626
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 me to chese between editing or deleting the item from the list view. That works fine. However, in addition to calling the context menu on Click,...
0
1108
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 in code. But, is there a way to effectively change the value of the Browsable attribute at run-time? For example, the ShouldSerialize and Reset...
4
2206
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 items to be edited in the Collection Editor (by clicking the button with the ellipses). But, for properties of type Array a PropertyGrid also allows...
0
1523
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 expand the property) and allow those values to be edited. My code is below. The grid is showing the values but they are read-only, although the other...
4
1618
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 designtime, but the property consists of enumerated constants used in bit operations, and when the values are exposed they show up as integers instead of the...
4
4029
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 possibly using the IPControl, and b) validate them on losing focus in the editing area. I've done a lot of googling, and frankly, I am now...
2
3797
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 the GridItem - I want to Select and focus on the value instead (even better would be to highlight text if it is a text value) Has anyone got any...
0
7518
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7711
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7467
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7805
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5367
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3497
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1932
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1054
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
755
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.