Using UITypeEditors with extended properties

  • Thread starter Thread starter Mario Vázquez
  • Start date Start date
M

Mario Vázquez

Hi,

I have a component which exposes an extended property. I want to edit this
property using a UITypeEditor. The problem is that when the designer raises
my UITypeEditor sends a reference of the component it's being edited (a
TextBox for example) but not of my component.
How can I receive a reference of the component that owns the extended
property?

Thanks a lot,
Mario Vázquez
 
Hi Mario,

That's a challenging problem and I am not sure about the need for this but
if you really need it you can try the following, not tested, just using the
debugger in my head ;-)

- Your class that inherits from UITypeEditor must override all the
overloaded methods EditValue, GetEditStyle, etc.

- Notice that each method has an overloaded variant which receives a context
(ITypeDescriptorContext). When these methods are called, store in a class
variable the following, to be used also when the other variant without the
context is called:

- The ITypeDescriptorContext.PropertyDescriptor property gives you the
property descriptor, which for an extended property like yours should be a
System.ComponentModel.ExtendedPropertyDescriptor, so cast it to this type.

- The ExtendedPropertyDescriptor class has 2 overloaded constructors: one
that receives the provider of the property (IExtenderProvider), which I
suppose that is an instance of your provider component. The other overloaded
constructor does not receive this parameter, though.

- The ExtendedPropertyDescriptor class does not expose the provider that it
stores when received through the constructor, but using Reflection, you can
retrieve the value of the field (the debugger of VS.NET 2002/2003 shows
private fields, so you can guess if you are on the track). Its signature is:

Private ReadOnly provider As IExtenderProvider

Good luck and let me know...

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com
 
Your mind debugger works fine!

I've got just want I wanted putting a breakpoint in the overrided function
EditValue of my UITypeEditor class, and asking for the following:

CType(CType(context.PropertyDescriptor,
ExtendedPropertyDescriptor).provider, MyExtenderProviderControl)

where context is the ExtendedPropertyDescriptor argument passed to this
function by the designer.

Well, I don't know much about reflection, so I need a little more help.
I understand that with reflection I can explore types and its members
dinamically, and even create instances of these types.
But, how can get an instance of an existing object?

Thank you for your help.

Regards,
Mario Vázquez
 
Hi Mario,

context.PropertyDescriptor already returns an instance of
ExtendedPropertyDescriptor. What you have to do is to use Reflection to get
the value of its private field "provider", something like this:

Dim objExtendedPropertyDescriptor As ExtendedPropertyDescriptor
Dim objType As Type
Dim objProvider As Object

objExtendedPropertyDescriptor = CType(context.PropertyDescriptor,
ExtendedPropertyDescriptor)
objType = objExtendedPropertyDescriptor.GetType
objProvider = objType.InvokeMember("provider",
Reflection.BindingFlags.GetField Or Reflection.BindingFlags.Instance Or
Reflection.BindingFlags.NonPublic, Nothing, objExtendedPropertyDescriptor,
Nothing)

And then objProvider is the instance of your provider control, isn´t it?

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com
 
Right! That's it!

Althought I have to change the code you give me like this:

Dim objType As Type
Dim objProvider As Object
Dim objMyExtendedPropertyControl As MyExtendedPropertyControl

' This line don't work
'objExtendedPropertyDescriptor = CType(context.PropertyDescriptor,
ExtendedPropertyDescriptor)

objType = context.PropertyDescriptor.GetType()
objProvider = objType.InvokeMember("provider", _
Reflection.BindingFlags.GetField Or Reflection.BindingFlags.Instance
Or _
Reflection.BindingFlags.NonPublic, Nothing,
context.PropertyDescriptor, Nothing)

objMyExtendedPropertyControl = CType(objProvider,
MyExtendedPropertyControl )

.... because the code editor does not let me declare any object of type
ExtendedPropertyDescriptor, because this type is private.

I've got it! So thanks a lot!

I'm trying to write a component which bind the controls on a form to a
DataSet. I use extended properties to specify in each control what property
it will be binded to each field on the dataSet. I need an UITypeEditor to
show a treeview of the dataset to bind, and also to show the right
properties for each control it's being binded.
I do all this because I've found no way to "hook" into the binding
working of the IDE. For example, when you drop a table on a DataSet design
surface, the IDE does'nt carry the relations to it. This make difficut to
generate the appropiate commands to Update and Delete a record from the
DataSet.... and things like this. Well, my english is poor and don't know if
i explain me right.
But maybe i'm wrong about all of this. Is there any way to generate a
tipped DataSet dinamically? This would simplifly the things...

Thank you again.

Regards,
Mario Vazquez
 
Hi Mario,
Right! That's it!

I'm glad that you got it.
ExtendedPropertyDescriptor, because this type is private.

Ah, yes, the type is actually Friend, the debugger in my head forgot it! ;-)
But maybe i'm wrong about all of this. Is there any way to generate a
tipped DataSet dinamically? This would simplifly the things...

I'm sorry but I don´t know, I mostly know about VS.NET extensibility
(although my MVP title says VB) but lately I have spent a lot of time
learning about UITypeEditors, etc. for a feature of my add-in and I was
caught by your question when I saw "UITypeEditors" in the subject, because I
have been solving similar tough problems :-)

A couple of recomendations:

- An excellent very long article (a whole chapter of a frustrated book
actually) about the design-time architecture of .NET:
http://www.codeproject.com/csharp/components.asp

- Using the .NET Reflector tool (http://www.aisto.com/roeder/dotnet/) you
can learn a lot about how the .NET Framework and VS work internally if you
see inside the proper assemblies (some of them are only in the GAC).

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com
 
Hello again, Carlos

Thank you for the information. I've download the Reflector tool and save the
article. I'll read it, because it seems so hard to find information about
inner working of the FrameWork and its relation with the ide of .net.
Another of the misteries that I have to clarify, is the DTE object. I guess
this is the type I need to create controls dinamically at design time, and
other interesting things like add and programatically manage projects,
dataSets and all the objects of the IDE.

Almost all the things I know about this questions I've learned from an
article about components. It talks about TypeConverters, Designers and so
on. I've tried to attach a zip file with this message but it has been
refused. I guess you know much more than me about this questions, but
perhaps you will find something interesting in this article. If you are
interessed, give me an address where I can send it to you.

Thanks for all.

Regards,
Mario Vazquez

(e-mail address removed)
 
Hello again, Carlos

I've downloaded Reflector tool and save the page about design-time
architecture. I'll read it, sure, because it's so hard to find information
concerning these inner questions of the .net
Another of the misterys that I must to clarify is the DTE object. I guess
this type is what I need to create dinamically controls on a form at design
time, among other things.

Almost all the things I know about this questions I've learned reading an
article about components: TypeDescriptors, TypeEditors, Designers and so on.
I've tried to attach a zip file with this message but it has been refused. I
guess that you know a lot about these questions, but perhaps you'd find
something interesting on it. If you are interessed, gve me an address to
send it to you.

Thanks for all.

Regards,
Mario Vazquez
(e-mail address removed)
 
Hello again, Carlos

I've downloaded Reflector tool and save the page about design-time
architecture. I'll read it, sure, because it's so hard to find information
concerning these inner questions of the .net
Another of the misterys that I must to clarify is the DTE object. I guess
this type is what I need to create dinamically controls on a form at design
time, among other things.

Almost all the things I know about this questions I've learned reading an
article about components: TypeDescriptors, TypeEditors, Designers and so on.
I've tried to attach a zip file with this message but it has been refused. I
guess that you know a lot about these questions, but perhaps you'd find
something interesting on it. If you are interessed, gve me an address to
send it to you.

Thanks for all.

Regards,
Mario Vazquez
(e-mail address removed)
 
Hi Mario,
Another of the misteries that I have to clarify, is the DTE object. I
guess this is the type I need to create controls dinamically at design
time, and other interesting things like add and programatically manage
projects, dataSets and all the objects of the IDE.

The EnvDTE.DTE class is the main class of the Visual Studio extensibility
model and it represents the IDE. Addins, external scripts and macros get an
instance of it by other means, but for what I learned, the designer of a
control can get an instance of it with a call to GetService(GetType(DTE)),
and yes, once you have a DTE you have DTE.Solution, DTE.Solution.Projects,
etc. You can see the object model in the Object Browser adding a reference
to the EnvDTE.dll assembly. My web site (below) has a section about add-ins
with resources about extensibility. If you need help in this area post again
(the microsoft.public.vstudio.extensibility is a better newsgroup) since it
is my area of expertise.
Almost all the things I know about this questions I've learned from an
article about components. It talks about TypeConverters, Designers and so
on. I've tried to attach a zip file with this message but it has been
refused. I guess you know much more than me about this questions, but
perhaps you will find something interesting in this article. If you are
interessed, give me an address where I can send it to you.

Sure, remove the NOSPAM part of my e-mail address in this message or contact
me through my web site.

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top