Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

223
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda