先加一个代码
public void SetXtraTabPageVisible(DevExpress.XtraTab.XtraTabControl xtraTabControl, bool iIsVisible, string strTabPageName) { // xtraTabControl1.Visible = true; foreach (DevExpress.XtraTab.XtraTabPage tabPage in xtraTabControl.TabPages) { if (tabPage.Name == strTabPageName) { tabPage.PageVisible = iIsVisible; } else { tabPage.PageVisible = !iIsVisible; } } }
这个能实现切换, 结果把另一个页面给彻底隐藏了,当前显示页到了隐藏页的位置, 隐藏的页的页头 也没得了位置,跟我想显示隐藏页的页头不符合.
改成这个方式问题解决
public void SetXtraTabPageVisible(DevExpress.XtraTab.XtraTabControl xtraTabControl, bool iIsVisible, string strTabPageName) { // xtraTabControl1.Visible = true; foreach (DevExpress.XtraTab.XtraTabPage tabPage in xtraTabControl.TabPages) { if (tabPage.Name == strTabPageName) { xtraTabControl.SelectedTabPage = tabPage;//显示该页 return; // tabPage.PageVisible = iIsVisible; } //else //{ // tabPage.PageVisible = !iIsVisible; //} } }
双击listview增加相应的tabpage,禁止重复添加:
private void listView_index_MouseDoubleClick(object sender, MouseEventArgs e) { if (listView_index.SelectedItems.Count > 0) { ListViewItem lvi = listView_index.SelectedItems[0];//得到选中的项 string name = lvi.Text; //判断是否已创建过 foreach (XtraTabPage page in xtraTabControl.TabPages) { if (page.Text == name) { xtraTabControl.SelectedTabPage = page;//显示该页 return; } } //增加tabpage XtraTabPage xpage = new XtraTabPage(); xpage.Name = name; xpage.Text = name; xpage.Controls.Add(ListView_Tec);//添加要增加的控件 xtraTabControl.TabPages.Add(xpage); xtraTabControl.SelectedTabPage = xpage;//显示该页 } }