简体   繁体   中英

How to access object from another tab c#

I have a tabcontrol on my winforms. On a tab page I have a combobox and on the another one I have a datagdridview . I need to get the text of a column of datagridview into combobox . The idea is that I don't know to have access at datagridview . It says that it is not in the current context.

This is how I have tried:

private void GetTextGrid()
    {
        combobox1.DataSource = gridview1.DataSource;
        combobox1.DisplayMember = "Column1";
        combobox1.ValueMember = "Column1";
    }

The datagridview has a DataSource set to some collection of items. Can't you just access that collection? If you dont have access to it where you need, you should easily be able to send it as a parameter.

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