Hello,
I am doing a side project to teach myself some c# and I am having some issues with Accessing Controls on a User control from a form and hope someone can help.
I made a user control (UCCities) with a TabControl through the designer. This will show up on every new tab that's created on my form form1.
The UC with TabControl will contain:
Tab 1(Units) contains a datagridview dgvUnits
Tab 2(Buildings) contains textbox and a label
Tab 3(Town) contains datagridview2 dgvTown.
I do not want to expose the whole control and want to setup properties. I am having trouble figuring out how to expose the datagrids properly so I can set up the columns text. Also the data is read from a text file from the form.
I was successful setting up the textbox and label properties but cant figure out how to properly call the UC and access the Datagrids from the form.
Do I have to make properties for every thing I want to change or control?
Just to make sure, is this the correct way to call the User control into one of the tabs on my form?
kpCity1 is a tabpage
UCCities test = new UCCites();
kpCity1.Controls.Add(test);
Here is UC code for the data grid that i tried.
public DataGridView DataGrid
{
get { return _dataGrid; }
set { _dataGrid = value; } Also tried the DatagridName.
}
And then on the form, no matter what I still don't have access to change settings. I either get an error saying there no instance for the object or no access rights..
So if anyone is confused to put it simple. I just want to Use a user control that has say a datagridview on it and access the UC and be able to modify the grid such as read and write data, change colmnames and etc...
Hope I explained enough o yeah I am not a student :)