Skip to main content
A newer version of this page is available. .

DXTabControl.SelectionChanging Event

Occurs before the selected tab item is changed.

Namespace: DevExpress.Xpf.Core

Assembly: DevExpress.Xpf.Core.v21.2.dll

NuGet Package: DevExpress.Wpf.Core

Declaration

public event TabControlSelectionChangingEventHandler SelectionChanging

Event Data

The SelectionChanging event's data class is TabControlSelectionChangingEventArgs. The following properties provide information specific to this event:

Property Description
Cancel Gets or sets a value indicating whether the event should be canceled. Inherited from CancelEventArgs.
NewSelectedIndex Gets the index of the tab item that is about to be selected.
NewSelectedItem Gets the tab item to be selected.
OldSelectedIndex Gets the index of the currently selected tab item.
OldSelectedItem Gets the currently selected tab item.

Remarks

Handle the SelectionChanging event to prevent selecting a tab item. To do this, set the event parameter’s TabControlSelectionChangingEventArgs.Cancel property to true.

To obtain which tab item is being selected, use the event parameter’s TabControlSelectionChangingEventArgs.NewSelectedIndex property. The index of the previously selected tab item is returned by the event parameter’s TabControlSelectionChangedEventArgs.OldSelectedIndex property. Use the DXTabControl.GetTabItem method to obtain a tab item by its index.

After a tab item has been selected, the DXTabControl.SelectionChanged event is fired.

Example

The following example shows how to prevent the tab items from being selected by handling the SelectionChanging event.In this example, selecting tab items, whose IsUrgent property is set to false, is not allowed.

View Example

using System;
using System.Collections.Generic;

namespace DXExample.DemoData {
    public enum InvoiceStatus { Ordered, Payed, Shipped, Delivered, Invalidated }
    public class Invoice {
        public int ID { get; set; }
        public string ProductName { get; set; }
        public double Price { get; set; }
        public DateTime OrderDate { get; set; }
        public double Discount { get; set; }
        public bool IsUrgent { get; set; }
        public InvoiceStatus Status { get; set; }
        static public List<Invoice> GetData() {
            List<Invoice> data = new List<Invoice>();

            data.Add(new Invoice() { ID = 0, ProductName = "Tofu", IsUrgent = false,
                Price = 235.54, Discount = 9.4, Status = InvoiceStatus.Invalidated,
                OrderDate = new DateTime(2009, 3, 12) });
            data.Add(new Invoice() { ID = 1, ProductName = "Ravioli Angelo", IsUrgent = true,
                Price = 178.45, Discount = 6.1, Status = InvoiceStatus.Delivered,
                OrderDate = new DateTime(2009, 2, 9) });
            data.Add(new Invoice() { ID = 2, ProductName = "Geitost", IsUrgent = false,
                Price = 89.98, Discount = 5.4, Status = InvoiceStatus.Payed,
                OrderDate = new DateTime(2009, 4, 1) });
            data.Add(new Invoice() { ID = 3, ProductName = "Chang", IsUrgent = true,
                Price = 189.33, Discount = 18.2, Status = InvoiceStatus.Shipped,
                OrderDate = new DateTime(2009, 5, 23) });
            data.Add(new Invoice() { ID = 4, ProductName = "Inlagd Sill", IsUrgent = false, 
                Price = 509.10, Discount = 22.2, Status = InvoiceStatus.Ordered,
                OrderDate = new DateTime(2009, 6, 30) });
            data.Add(new Invoice() { ID = 5, ProductName = "Alice Mutton", IsUrgent = true,
                Price = 791.18, Discount = 24.4, Status = InvoiceStatus.Invalidated,
                OrderDate = new DateTime(2009, 5, 7) });

            return data;
        }
    }
}
See Also