Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

224
Views
Is it possible to limit exposed properties of embedded control UserControl

So there is the UserControl in windows forms that allows you to create more complex creations.

public class MyUserControl : UserControl
{
    public MyUserControl() 
    {
        IniitalizeComponents();
    }

    private void InitializeComponents() 
    {
       this.datagridview1 = new System.Windows.Form.DataGridView();
       this.Controls.Add(this.dataGridView1);
    }
    private System.Windows.Forms.DataGridView dataGridView1;
}

Pretty straight forward. However sometimes you want to expose elements of that internal control. So like I can put a "DataSource" on my Usercontrol and wire that into the dataGridView1.

public object DataSource {get => dataGridView1.DataSource; set => dataGridView1.DataSource = value;}

I can even, if I don't want to have to manually expose each and every property of the embedded control, I could expose the control via a referenced property:

[Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public DataGridView GridControl => this.dataGridView1;

The problem with this is that it exposes ALL the properties and events of the control.
Enter the custom designer.

[Designer(typeof(MyDGVDesigner)] 
public class CustomDataGridView : DataGridView 
{
}

class MyDGVDesigner : ControlDesigner 
{
    protected override PreFilterProperties(IDictionary properties)
    {
        properties.Remove(nameof(DataGridView.DataSource));
    }
}

And now the "Grid" that is exposed by my UserControl no longer displays the DataSource property.
However, this is the problem. While designing my UserControl, the property is also hidden for the private field. I want to "limit" the properties/events exposed to the ProperyGrid at the "GridControl" property level for when the UserControl is added to a form externally, but not at the forms designer for the UserControl where i am manipulating the private dataGridView1.

Is this even possible? If so, how would I achieve it?

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!