简体   繁体   English

使用列表框选择索引在TabControl上选择Tab

[英]Selecting Tab on TabControl using listbox selected Index

I am currently using a tabControl and a listbox independantly of each other. 我目前彼此独立地使用tabControl和列表框。

The tab control has 5 pages on it. 选项卡控件上有5页。 The Listbox has the list of the 5 page titles. 列表框包含5个页面标题的列表。

Edit: I am essentially trying to set the select page of the FundNavigator to be the same as the one selected in the Listbox. 编辑:我实际上是试图将FundNavigator的选择页面设置为与列表框中选择的页面相同。 So if item number 3 in the list box is selected then I want tab number 3 to be displayed as the selected page. 因此,如果选择了列表框中的项目编号3,那么我希望将标签编号3显示为所选页面。

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. 我想要得到它,因此当您在ListBox中选择页面标题之一时,它将切换到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 这样我就得到了ArgumentOutOfRangeException尽管它说

"index out of range. Parameter Name: value" “索引超出范围。参数名称:值”

Could somebody help me fix this problem? 有人可以帮我解决这个问题吗?

FundNavigator.SelectedIndex = ListBox1.SelectedIndex

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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