Problem using a getting the parent name of a control when using form inheritance

  • Thread starter Thread starter Andrew Baker
  • Start date Start date
A

Andrew Baker

I want to show the parent name of a control in an addin I am writing.
However, when I use the following :

string parentName = thisControl.Parent.Name // thisControl is of type
Control

it is returning the name of the base type. Below is the form class
declaration:

public class frmUserEditor : VBUsers.Windows.Forms.EditorFormBase
{
....
}

ie. It returns the name of EditorFormBase rather than the name of
frmUserEditor.

Does anyone know why this is happening and how to get the name of the
most derived container of the control?

tia

andrew
 
It's my guess that your parent form, EditorFormBase, has a set of controls
on it, and the control you are testing is one of them.
In this case, the behavior your are experiencing is expected.

You could always derive a control subclass that allows you to set a
typename. In the constructor for your form class, you can pass in the name
of the class, and assign that name to each of your controls, regardless of
where they are declared.

(just a suggestion)

Hope this helps,
--- Nick
 
Thank Nick but that's not the case, they are only on the derived
form... Anyone else any ideas?

andrew
 
Back
Top