C # Dynamically add tab and Close tabs

Source: Internet
Author: User
Tags xpage

Keep a record so you don't forget it later.

Add a using Devexpress.xtratab;

Double-click ListView to add the appropriate TabPage and prevent duplicate additions:

The code is as follows Copy Code

private void Listview_index_mousedoubleclick (object sender, MouseEventArgs e)
{
if (Listview_index. Selecteditems.count > 0)
{
ListViewItem LVI = Listview_index. selecteditems[0];//Gets the selected item
String name = Lvi. Text;
Determine if you have created
foreach (Xtratabpage page in xtratabcontrol.tabpages)
{
if (page. Text = = name)
{
Xtratabcontrol.selectedtabpage = page;//Show this page
Return
}
}
Increase TabPage
Xtratabpage xpage = new Xtratabpage ();
Xpage. name = name;
Xpage. Text = name;
Xpage. Controls.Add (Listview_tec)//Add the control to be added
XTRATABCONTROL.TABPAGES.ADD (Xpage);
Xtratabcontrol.selectedtabpage = xpage;//Show this page
}
}

To TabPage display the Close button, set the Xtratabcontrol Closepagebuttonshowmode property to Inalltabpageheaders; If you want the first page to not show the Close button:

Xtratab_index. Showclosebutton = devexpress.utils.defaultboolean.false;//The home page does not show the Close button

To add a Xtratabcontrol Closebuttonclick event:

The code is as follows Copy Code

private void Xtratabcontrol_closebuttonclick (object sender, EventArgs e)//Close Tab method
{
DevExpress.XtraTab.ViewInfo.ClosePageButtonEventArgs Earg = (DevExpress.XtraTab.ViewInfo.ClosePageButtonEventArgs E
String name = earg.page.text;//Gets the Text of the tab that is closed
foreach (Xtratabpage page in xtratabcontrol.tabpages)//traverse the same text that gets and closes the tab
{
if (page. Text = = name)
{
XtraTabControl.TabPages.Remove (page);
Page. Dispose ();
Return
}
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.