How do I get access to the parent controls of user control in C# (winform). I am using the following code but it is not applicable on all types controls such as ListBox.
Control[] Co = this.TopLevelControl.Controls.Find("label7", true);
Co[0].Text = "HelloText"
Actually, I have to add items in Listbox placed on parent ‘Form’ from a user control.
Description
You can get the parent control using
Control.Parent.Sample
So if you have a Control placed on a form
this.Parentwould be your Form.Within your Control you can do
More Information
Update after a comment by Farid-ur-Rahman (He was asking the question)
You have two possible ways to get this done.
1. Use `Control.Parent
Sample
MyUserControl
or
2.
public MyForm ParentForm { get; set; }to yourUserControlListBoxis namedlistBox1otherwise change the nameSample
MyForm
MyUserControl