C#-dev Xtratabcontrol dynamically Add tab and close tab methods

Source: Internet
Author: User
Tags xpage

C#-dev xtratabcontrol Dynamic Add tab and Close Tab method, there is a need for friends to refer to below.

Keep a record so you don't forget.

Add using Devexpress.xtratab;

Double-click the ListView to add the appropriate tabpage, and disallow repeated additions:

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;                Determines whether a                foreach (Xtratabpage page in xtratabcontrol.tabpages)                {                    if (page) has been created. Text = = name)                    {                        xtratabcontrol.selectedtabpage = page;//Display the page                        return;                    }                }                Increase TabPage                xtratabpage xpage = new Xtratabpage ();                Xpage. name = name;                Xpage. Text = name;                Xpage. Controls.Add (Listview_tec);//Add the Control                xtraTabControl.TabPages.Add (xpage) to be added;                Xtratabcontrol.selectedtabpage = xpage;//Display the page            }        }

To tabpage the Close button, set the Closepagebuttonshowmode property of the Xtratabcontrol to Inalltabpageheaders, or the Close button if you want the home page to appear:

Xtratab_index. Showclosebutton = devexpress.utils.defaultboolean.false;//Home does not show Close button

To add the Xtratabcontrol Closebuttonclick event:

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 closed tab of the Text            foreach (Xtratabpage Page in xtratabcontrol.tabpages)// Iterate through the same tab that gets and closes the text            {                if (page. Text = = name)                {                    xtraTabControl.TabPages.Remove (page);                    Page. Dispose ();                    return;}}}        

C#-dev Xtratabcontrol dynamically add tab and close tab methods

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.