开发者

Weird listview behavior?

开发者 https://www.devze.com 2023-01-10 12:11 出处:网络
This issue is driving me crazy.. This code raises index out of range exception for the messagebox: private void MainTabs_Selected(object sender, TabControlEventArgs e)

This issue is driving me crazy..

This code raises index out of range exception for the messagebox:

    private void MainTabs_Selected(object sender, TabControlEventArgs e)
    {
        if (MainTabs.SelectedTab.Name == "ActiveDirectoryTab")
        {
            ADServerSelect.Items[0].Selected = true;
            MessageBox.Show(ADServerSelect.Items[0].Text);
        }
    }

But if the messagebox is the result of an event it works just fine:

    private void MainTabs_Selected(object sender, TabControlEventArgs 开发者_如何学Ce)
    {
        if (MainTabs.SelectedTab.Name == "ActiveDirectoryTab")
        {
            ADServerSelect.Items[0].Selected = true;
        }
    }

    private void testButton_Click(object sender, EventArgs e)
    {
        MessageBox.Show(ADServerSelect.Items[0].Text); 
    }

Any help would be greatly appreciated..


looks like items added to the listview AFTER MainTabs_Selected event. can you check it?

0

精彩评论

暂无评论...
验证码 换一张
取 消