Yenthe
Yenthe

Reputation: 2353

Making properties available in datagridview usercontrol c#

Since a few days I've started coding a datagridview with paging. The paging itself works and calculates well. But now I've ran into a problem, I need properties from my custom made user control that aren't available.

In order to be able to use my selfmade usercontrol I need the following properties to be available when exporting it into a .dll file (usercontrol):

Could anybody please help me along the way on how to do this / give examples? I have no idea how to get this going.

I've got one property working that I also needed, so I guess this could work as an example :)

public void SetColumns( string columnName)
{
    dataGridView.Columns[columnName].Visible = false;
}

To make it short: how can I get those properties available in my other projects by coding it in the datagridview? It'll be an usercontrol.

Thank you, Yenthe

Upvotes: 0

Views: 1215

Answers (1)

Gabriel GM
Gabriel GM

Reputation: 6639

The answer would depends on what exactly you need.
The first scenario would involve exposing the DataGridView itself to the user. In your UserControl:

private DataGridView _dataGridView1;

//Lets use a readonly property for this one
//Be careful, readonly property doesn't mean you can't modify the values inside!
public DataGridView UserControlDataGridView 
{
    get
    {
        return _dataGridView1;
    } 
}

Then, you'd have control over your DataGridView in your other project.

If you don't want to expose your DataGridView to the user, you'd need to create a property for each item you want.

Hope this helps!

Upvotes: 0

Related Questions