C#TabControl文件找不到
我有一个我不明白的问题。我有一个带有2个选项卡的TabControl。
选项卡1:Tab 1 in IT选项卡
2:Tab 2:在TAB 2中使用ChecllistBox的选项卡
,我在TAB 2中,我在没有问题的情况下运行此代码:
foreach (int i in groupeCheckedListBox.CheckedIndices)
{
groupeCheckedListBox.SetItemCheckState(i, CheckState.Unchecked);
}
但是,如果我在选项卡1中,它找不到ChecklistBox因此,我决定编写此代码:
if (tabControl1.SelectedTab == tabControl1.TabPages[1])
{
foreach (int i in groupeCheckedListBox.CheckedIndices)
{
groupeCheckedListBox.SetItemCheckState(i,CheckState.Unchecked);
}
}
但是当我运行它时,我会收到一个错误:
“ system.componentmodel.win32 exception :'le fichierspécifiéest in Intouvable'
意味着它无法在行中找到文件” if(tabcontrol1.selectedtab == tabcontrol1.tabcontrol1.tabpages [1])。
这
tabControl1.SelectedTab = tabControl1.TabPages[1];
并
TabPage t = tabControl1.TabPages[0];
tabControl1.SelectTab(t);
以相同的结果
来解释我为什么找不到文件?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Winforms中的HMMM选项卡控件可能很棘手,您是否将此逻辑放在选项卡康德罗(TabControl)上的SelectedIndexchanged事件中?然后,您应该能够检查索引值并确定您有活动的选项卡,并且每个选项卡中的控件都应始终可访问和实例化,我能够将SelectedTab检查到预期的TabPage,并评估为true:
Hmmm tab controls in Winforms can be tricky, are you putting this logic in the SelectedIndexChanged event on the TabControl? Then you should be able to check the index value and determine which tabPage you have active and the controls in each tab should always be accessible and instantiated, I was able to check the selectedTab to the tabPage expected and it evaluated true: