简体   繁体   中英

c# access and update datagridview data from another user control

I have an application, that has 2 usercontrols

In the first usercontrol, there is a datagridview and within that, there is a function that gets the data and fills the datagridview.

public void getdata()
        {
            //get data and fill datagrid view...
        }

This function is being called on usercontrol load


In the 2nd user control, after doing registration, etc. I want to call the getdata() function again so the datagridview is updated in 1st usercontrol.

so this is what I tried:

Code_Sign uc = new Code_Sign();
uc.getdata();

//code_sign is name of 1st usercontrol

Doing this, the function is called (I tested this by putting a msgbox in the function. The msgbox is displayed)

However, the problem is this. The datagrid view has no changes, eg the new data is not inserted into the datagridview. Same old data is displayed.

in the getdata() function. I have

bunifuCustomDataGrid1.Rows.Add(
                new object[]
                {
                    issuer,
                    data,
                    x509.SerialNumber,
                    x509.FriendlyName
                }
                );

(I have also tested this with normal datagridview instead of bunifudatagrid. It doesn't work)

I have set modifier of datagrid view to public but i just can't seem to have it working in any way.

Any help would be appreciate. I'm not sure what I am missing. Maybe there is another way which I am not aware of.

Thanks in advance

Don't create new instance of Code_Sign in 2nd usercontrol. From the 2nd userconntrol you need to get the very first instance of Code_Sign and try to call the getdata() function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM