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

Using UITypeEditors with extended properties

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
Nov 23 '05 #1
9 2396
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

"Mario Vázquez" <al*****@microsoft.com> escribió en el mensaje
news:OS**************@TK2MSFTNGP14.phx.gbl...
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

Nov 23 '05 #2
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
"Carlos J. Quintero [VB MVP]" <ca*****@NOSPAMsogecable.com> escribió en el
mensaje news:eV**************@TK2MSFTNGP12.phx.gbl...
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

"Mario Vázquez" <al*****@microsoft.com> escribió en el mensaje
news:OS**************@TK2MSFTNGP14.phx.gbl...
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


Nov 23 '05 #3
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
"Mario Vázquez" <al*****@microsoft.com> escribió en el mensaje
news:us**************@TK2MSFTNGP12.phx.gbl...
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


Nov 23 '05 #4
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

"Carlos J. Quintero [VB MVP]" <ca*****@NOSPAMsogecable.com> escribió en el
mensaje news:O3***************@TK2MSFTNGP10.phx.gbl...
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
"Mario Vázquez" <al*****@microsoft.com> escribió en el mensaje
news:us**************@TK2MSFTNGP12.phx.gbl...
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

Nov 23 '05 #5
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
Nov 23 '05 #6
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

mv******@girosystem.com
"Carlos J. Quintero [VB MVP]" <ca*****@NOSPAMsogecable.com> escribió en el
mensaje news:OJ***************@TK2MSFTNGP09.phx.gbl...
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

Nov 23 '05 #7
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
mv******@girosystem.com

"Carlos J. Quintero [VB MVP]" <ca*****@NOSPAMsogecable.com> escribió en el
mensaje news:OJ***************@TK2MSFTNGP09.phx.gbl...
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

Nov 23 '05 #8
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
mv******@girosystem.com

"Carlos J. Quintero [VB MVP]" <ca*****@NOSPAMsogecable.com> escribió en el
mensaje news:OJ***************@TK2MSFTNGP09.phx.gbl...
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


Nov 23 '05 #9
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
Nov 23 '05 #10

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

Similar topics

2
by: Roland Hall | last post by:
I have two(2) issues. I'm experiencing a little difficulty and having to resort to a work around. I already found one bug, although stated the bug was only in ODBC, which I'm not using. It...
14
by: Roland Hall | last post by:
I have two(2) issues. I'm experiencing a little difficulty and having to resort to a work around. I already found one bug, although stated the bug was only in ODBC, which I'm not using. It...
3
by: Roland Hall | last post by:
Three times the charm? Sorry for the repost. Trying to get my account right. I have two(2) issues. I'm experiencing a little difficulty and having to resort to a work around. I already...
9
by: Guy | last post by:
I have extended the datetimepicker control to incorporate a ReadOnly property. I have used the new keyword to implement my own version of the value property, so that if readonly == true then it...
1
by: funcSter | last post by:
I want to retrieve data from an Excel file like how I would with a database. I understand that I would have to use OLE DB. Somehow I think I cannot get the connection string right, as the bit of...
1
by: svijay | last post by:
hi I have got a strange problem. May I know any solution for this. Here is the detailed description about the problem We have got a mainframe system and also production and development...
0
by: jcvoon | last post by:
Hi: How to notify extended properties provider when the component is removed ? so that i can deleted the entry for that component from extended properties holder (the collection use to hold all...
3
by: Ben | last post by:
Hi! I have a user on my database that has only "select" access (db_datareader). Problem is, I also want him to also be able to create/update extended properties on tables or views, but without...
11
by: sweetpotatop | last post by:
Hi, I wonder if it is possible to read the content of an excel spreadsheet through aspnet. The spreadsheet (workbook) is protected and it resides in a network drive. Please provide sample...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.