Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

226
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda