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?