Composite Component in C# does not show all attributes

Asked

Viewed 82 times

0

I have a system where I use a dataGridView to list the fields of a table through the property dataSource, and a textBox so that the written text serves as a filter (when I type something in textBox, use typed text to filter my table and update on dataSource of dataGridView).

I am learning C# and saw that in Visual Studio, I can create a Composite Component and wanted to create a component textBox and the dataGridView.

I started the creation with a dataGridView and a textBox and managed the new component (textBoxGrid).

Includes the new component (textBoxGrid) in my form and when I went looking for the property dataSource in the new component, it is not shown.

How do I make her visible?

1 answer

4


You must create a "link" between your property datagridview and its component.

Something like this:

In your component just create a property with get, and set pointing to the property of the datagridview:

If you need to set the DataSource in design mode, the attributes should be added to the property.

[AttributeProvider(typeof(IListSource)), DefaultValue(null), RefreshProperties(RefreshProperties.Repaint)]
public Object DataSource
{
    get { return datagridview1.DataSource; }
    set { datagridview1.DataSource = value; }
}

See with the attribute in the property, the datasource is "unlocked"

inserir a descrição da imagem aqui

Remember that every time you change the component you must give build in the project again to update.

  • I’ll test it right now. I can do it with any property?

  • Yes you can do this with any property, including you can open the get and set, to manipulate as you wish by inserting if, for example.

  • You carry the DataSource in the design of visual studio or at runtime?

  • It worked!!! Thank you very much. I press on the design.

  • If you are going to click on the design you may need to add the attributes to the property. As is Object the property will appear but it will not be possible to change. I will change the answer.

  • blz, I’m waiting for you to change

  • Thanks, if it’s not too much to ask, can you explain that line? -> [Attributeprovider(typeof(Ilistsource)), Defaultvalue(null), Refreshproperties(Refreshproperties.Repaint)]

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.