473,383 Members | 1,818 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,383 software developers and data experts.

Re: Custom ITypeDescriptorContext

The context is passed from the caller, in this case the PropertyGrid -
but you shouldn't need to have a custom context unless you are writing
your own UI implementation. Normally, the trick is to look at the
context's Instance and PropertyDescriptor (if they are set) which gives
you the object and property being processed. A typical use-case would be
to look at the PropertyDescriptor for metadata (attributes etc).

If you let me know what you need to do in more detail I might be able to
help more (I'm painfully familiar with System.ComponentModel).

Note also that some simpler data-binding implementations (like
DataGridView) pass a null context; you should be fine from PropertyGrid,
though.

Marc
Jul 14 '08 #1
2 5327
Marc Gravell wrote:
The context is passed from the caller, in this case the PropertyGrid -
but you shouldn't need to have a custom context unless you are writing
your own UI implementation. Normally, the trick is to look at the
context's Instance and PropertyDescriptor (if they are set) which gives
you the object and property being processed. A typical use-case would be
to look at the PropertyDescriptor for metadata (attributes etc).

If you let me know what you need to do in more detail I might be able to
help more (I'm painfully familiar with System.ComponentModel).

Note also that some simpler data-binding implementations (like
DataGridView) pass a null context; you should be fine from PropertyGrid,
though.

Marc
Thanks for your help Marc, I got it now:

public override object ConvertFrom(ITypeDescriptorContext context,
CultureInfo info, object value)
{
if (value is string)
{
if (context != null)
{
PropertyDescriptor pd = context.PropertyDescriptor;
FixedLengthString fs =
(FixedLengthString)context.Instance.GetType().GetP roperty(pd.Name).GetValue(context.Instance,
null);
if (fs != null)
return new FixedLengthString((string)value, fs.Capacity);
}
}
return base.ConvertFrom(context, info, value);
}

Jul 14 '08 #2
Re the "get" code... how about:

FixedLengthString fs = (FixedLengthString)
pd.GetValue(context.Instance);

PropertyDescriptor is an abstract "property" implementation; by
default it uses reflection under the bonnet, so you don't need to use
reflection yourself. This approach also means that your code will work
with more exotic property systems [of which many are possible...].

Marc
Jul 15 '08 #3

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

Similar topics

4
by: CroDude | last post by:
I've made a custom groupbox control. Inside, as one of it's members is CSimpleGradient object. CSimpleGradient is a wrapper class for gradient usage. Basically it looks like that: public class...
0
by: Tom | last post by:
I am developing a page that will contain multiple instances of a Composite Custom Control that i have developed. The problem is that the user will determine at run time how many of the control...
1
by: Sky Sigal | last post by:
(PS: Cross post from microsoft.pulic.dotnet.framework.aspnet.webcontrols) I've been looking lately for a way to keep the Properties panel for Controls 'clean'... My goal is to keep similar...
5
by: ToddH | last post by:
I know the following code is C#. I'm a vb programmer trying to learn a new language. I posted this in the c# group but never got a response. You guys seem to know alot about all languages and have...
2
by: AMDRIT | last post by:
Hello everyone, I have created a custom component and one of its properties is a class object with it's own properties. During runtime, I can assign values to the class object properties just...
0
by: Kay | last post by:
Hello, I have developed a web custom control, I want one of the properties of the control to appear as a dropdown list so the user can select from the list. My question is: how do I define an...
0
by: Jeremy Chapman | last post by:
I have included below virtually all the code to a control I'm trying to build. My issue is that an array list property in my control does not get persisted properly to the aspx page code in design...
0
by: Kay | last post by:
Hello, I have written my own custom control and I want one of its properties to display as a dropdown list when clicked, so the user can select from the list, it would be similar to the asp...
0
by: Kay O'Keeffe | last post by:
Hello, I have written my own custom control and I want one of its properties to display as a dropdown list when clicked, so the user can select from the list, it would be similar to the asp...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.