简体   繁体   中英

Selecting Tab on TabControl using listbox selected Index

I am currently using a tabControl and a listbox independantly of each other.

The tab control has 5 pages on it. The Listbox has the list of the 5 page titles.

Edit: I am essentially trying to set the select page of the FundNavigator to be the same as the one selected in the Listbox. So if item number 3 in the list box is selected then I want tab number 3 to be displayed as the selected page.

I want to get it so when you select one of the page titles in the ListBox, it will switch to that tab in the TabControl. I had tried a couple of way, this felt the closest:

    public void LoadMatchingTab()
    {
        listIndex = ListBox1.SelectedIndex;
        FundNavigator.SelectedIndex = FundNavigator.Pages.IndexOf(listIndex);
    }

    private void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        LoadMatchingTab();
    }

With this I am gettinf an ArgumentOutOfRangeException though andit says

"index out of range. Parameter Name: value"

Could somebody help me fix this problem?

FundNavigator.SelectedIndex = ListBox1.SelectedIndex

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