Windows Develop Bookmark and Share   
 index > Windows Forms Designer > IExtenderProvider: how to get a reference to the original extended controls
 

IExtenderProvider: how to get a reference to the original extended controls

Hi,

I have createdan extendercontrol which adds ReadOnly capabilities to various controls.
For certain functionalities I have to Read certain Properties of the extendee (the original Control).
So let's say I have a ComboBox (cmbTest)on a Form which is extended by MyExtenderControl.
When the'cmbTest' gets extended and thus added to mExtendControls, an internal HashTable of MyExtenderControl, I need to read the 'Enabled' property of'cmbTest'.
Simplycasting the extendee to whatever type of control it is, doesn'twork because all Properties are 'default' then.
This all has to be done at runtime.

I guess I'm missing something very simple and obvious here.
TIA,

Michael
Michaël Maes  Tuesday, June 23, 2009 9:14 PM
Hi Michaël Maes,

Just use your example. Did you add ComboBox(cmbTest) to the user control(MyExtenderControl)? If my guess is correct, you need to expose the property so it can be modified outside. Like this.
public partial class MyExtenderControl : UserControl
{
public MyExtenderControl()
{
InitializeComponent();
}

public ComboBox CmbTest
{
get { return this.comboBox1; }
set { this.comboBox1 = value; }
}
}

If I misunderstood you, please feel free to tell me.

Sincerely,
Kira Qian
Please mark the replies as answers if they help and unmark if they don't.
Kira Qian  Thursday, June 25, 2009 3:53 AM

Hi Kira,

Thanks for your reply and sorry for my late respons!
No, my scenario is different: I inherit from 'Component' and Implement 'IExtenderProvider'.

Inherits System.ComponentModel.Component

Implements IExtenderProvider

My ExtenderControl manages all data-entry controls on the form and also buttons, ToolBars, etc...

So there can be tens of ComboBoxes in the ExtenderControls' HashTable.

Right before added the Extended Control to the Hashtable, I lookup some properties like this:

' Creates a new collection and assign it the properties for the Extendee.

Dim properties As PropertyDescriptorCollection = TypeDescriptor.GetProperties(extendee)

' Sets an PropertyDescriptor to the specific property.

Dim myProperty As PropertyDescriptor = properties.Find("LimitToList", False)

Dim LimitToList As Boolean = False

Boolean.TryParse(myProperty.GetValue(extendee), LimitToList)

ProvidedProperties.LimitToList = LimitToList

But the problem here seems to be that the Extendee has not a true reference to the control on the form, so all it's properties will always be the Default Value.

I use the GetPropertyName / SetPropertyName / ShouldSerializePropertyName to pass the Control to the Hashtable.

I'm pretty much sure I'm doing something wrong somewhere because it doesn't seem logical to me.

TIA,

Michael

Michaël Maes  Monday, June 29, 2009 7:01 PM

You can use google to search for other answers

Custom Search

More Threads

• Form, Panel or UserControl
• write a string directly on flash drive
• issue : Grid Scrollbar maintain scroll bar position after refresh Grid
• Creating my own TabPage class
• cloning a listview
• Change Pointvalue in a PropertyGrid during runtime
• Design view slow to load
• How to do parallel transactions in SQL server database using VB.Net 2005?
• 3 layers.
• (URGENT)