I'm a beginner in C#. I have a DataGridvew "dgPins" defined in a class along with a Panel named "pnlPins". The application is designed using several UIs combined together. The initializing is done in class X as follows
private void InitializeComponent() {
...
private System.Windows.Forms.Panel pnlPINs;
private System.Windows.Forms.DataGridView dgPins;
...
}
I use this grid to display some pins read from a device connected to Ethernet. Once the data is filled it looks like this(this is done with a button click),
private void mnuGeraetLesen_Click(object sender, EventArgs e)
{
...
if (EthernetAvailable == true)
{
QueryAllCodeCommandHandler();// local function which fills the grid
}
}
Now in another UI(class) I have a button which needs to access the same grid instance and do the same task. So I have done the following in that class(let's say class Y).
private void _btnSearchDevices_Click(object sender, EventArgs e)
{
SingleDeviceInformationControl test = new SingleDeviceInformationControl();
test.QueryAllCodeCommandHandler();
}
But as I understand this will create a different instance and will not work. So the grid remains empty as below.
I thought of renaming the dataGridview to public static which enables me to access the same instance from anywhere but it makes the whole project unstable. I have done some research and found similar questions but haven't understood what I really have to do to achieve the expected result. I really appreciate any hints for a possible solution for this issue. Thank you very much!