Link to home
Start Free TrialLog in
Avatar of ANINDYA
ANINDYAFlag for India

asked on

How to access the tab header name?

Experts
I want to get the name of the header name of the tab while clicking the tab .
The code by which I am creating the new tab is as followes:
private void mnuSave_Click(object sender, Telerik.Windows.RadRoutedEventArgs e)
        {
            try
            {
                this.txtTabName.Text = string.Empty;
                winNewTabname.Header = "Set Name of Tab";
                winNewTabname.Top = this._mousePosition.Y;
                winNewTabname.Left = this._mousePosition.X - 200;
                winNewTabname.WindowStartupLocation = WindowStartupLocation.Manual;
                winNewTabname.ResizeMode = ResizeMode.NoResize;
                winNewTabname.Closed += new EventHandler<WindowClosedEventArgs>(winNewTabname_Closed);
                winNewTabname.ShowDialog();
            }
            catch (Exception ex)
            {
                Globals.HandleUIExceptions(ex);
            }
        }
        private void winNewTabname_Closed(object sender, WindowClosedEventArgs e)
        {
            if (e.DialogResult == true && !string.IsNullOrEmpty(this.txtTabName.Text.Trim()))
            {
                var found = from Object obj in tabNotes.Items
                            where (obj as RadTabItem).Header.ToString() == this.txtTabName.Text.Trim()
                            select obj;

                if (found.ToList().Count == 0)
                {
                    RadTabItem tabItem = new RadTabItem();
                    tabItem.Tag = this.txtTabName.Text;
                    tabItem.Header = this.txtTabName.Text;
                    tabNotes.Items.Add(tabItem);
                    this.tabNotes.SelectedIndex = tabNotes.Items.Count - 1;
                    RadContextMenu.SetContextMenu(tabItem, _ContextMenu);
                }
                else
                {

                    this.tabNotes.SelectedItem = found.ToList()[0] as RadTabItem;
                }
            }
        }

Now please suggest me how to get the tag name
 User generated image
private void mnuSave_Click(object sender, Telerik.Windows.RadRoutedEventArgs e)
        {
            try
            {
                this.txtTabName.Text = string.Empty;
                winNewTabname.Header = "Set Name of Tab";
                winNewTabname.Top = this._mousePosition.Y;
                winNewTabname.Left = this._mousePosition.X - 200;
                winNewTabname.WindowStartupLocation = WindowStartupLocation.Manual;
                winNewTabname.ResizeMode = ResizeMode.NoResize;
                winNewTabname.Closed += new EventHandler<WindowClosedEventArgs>(winNewTabname_Closed);
                winNewTabname.ShowDialog();
            }
            catch (Exception ex)
            {
                Globals.HandleUIExceptions(ex);
            }
        }
        private void winNewTabname_Closed(object sender, WindowClosedEventArgs e)
        {
            if (e.DialogResult == true && !string.IsNullOrEmpty(this.txtTabName.Text.Trim()))
            {
                var found = from Object obj in tabNotes.Items
                            where (obj as RadTabItem).Header.ToString() == this.txtTabName.Text.Trim()
                            select obj;

                if (found.ToList().Count == 0)
                {
                    RadTabItem tabItem = new RadTabItem();
                    tabItem.Tag = this.txtTabName.Text;
                    tabItem.Header = this.txtTabName.Text;
                    tabNotes.Items.Add(tabItem);
                    this.tabNotes.SelectedIndex = tabNotes.Items.Count - 1;
                    RadContextMenu.SetContextMenu(tabItem, _ContextMenu);
                }
                else
                {

                    this.tabNotes.SelectedItem = found.ToList()[0] as RadTabItem;
                }
            }
        }
        private void winRenameTabname_Closed(object sender, WindowClosedEventArgs e)
        {
         }


//here is the full code 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls;
using UBS.Rx.Presentation.Common;

namespace UBS.Rx.Presentation.UI.Moola
{
    public partial class TabbedNotesControl : UserControl
    {
        Notes _Notes;
        double _Height, _Width;
        int _Selectedindex = -1;
        Point _mousePosition = new Point(0, 0);
        RadContextMenu _ContextMenu;

        public TabbedNotesControl()
        {
            InitializeComponent();
            _Notes = new Notes();
            StyleManager.SetTheme(this.tabNotes, ThemeManager.FromName(Globals.MoolaThemeName));
            this.tabNotes.SelectionChanged += new RoutedEventHandler(tabNotes_SelectionChanged);
            mnuSave.Click += new Telerik.Windows.RadRoutedEventHandler(mnuSave_Click);
            this.txtTabName.KeyDown += new KeyEventHandler(txtTabName_KeyDown);
            this.MouseMove += new MouseEventHandler(TabbedNotesControl_MouseMove);
            _ContextMenu = new RadContextMenu();
            RadMenuItem mnuTabItemAdd = new RadMenuItem() { Name = "mnuTabItemAdd", Header = "Add a new tab" };
            _ContextMenu.Items.Add(mnuTabItemAdd);
            mnuTabItemAdd.Click += new Telerik.Windows.RadRoutedEventHandler(mnuSave_Click);


            RadMenuItem mnuTabItemRemove = new RadMenuItem() { Name = "mnuTabItemRemove", Header = "Remove tab" };
            _ContextMenu.Items.Add(mnuTabItemRemove);
            mnuTabItemRemove.Click += new Telerik.Windows.RadRoutedEventHandler(mnuTabItemRemove_Click);

            RadMenuItem mnuTabItemRename = new RadMenuItem() { Name = "mnuTabItemRename", Header = "Rename tab" };
            _ContextMenu.Items.Add(mnuTabItemRename);
            mnuTabItemRename.Click += new Telerik.Windows.RadRoutedEventHandler(mnuTabItemRename_Click);
        }

        private void mnuTabItemRename_Click(object sender, Telerik.Windows.RadRoutedEventArgs e)
        {
            //Rename
            try
            {
                this.txtTabName.Text = string.Empty;
                winNewTabname.Header = "Rename Tab";
                winNewTabname.Top = this._mousePosition.Y;
                winNewTabname.Left = this._mousePosition.X - 200;
                winNewTabname.WindowStartupLocation = WindowStartupLocation.Manual;
                winNewTabname.ResizeMode = ResizeMode.NoResize;
                winNewTabname.Closed += new EventHandler<WindowClosedEventArgs>(winRenameTabname_Closed);
                winNewTabname.ShowDialog();
            }
            catch (Exception ex)
            {
                Globals.HandleUIExceptions(ex);
            }
        }

        private void mnuTabItemRemove_Click(object sender, Telerik.Windows.RadRoutedEventArgs e)
        {
           //Remove
        }

        private void TabbedNotesControl_MouseMove(object sender, MouseEventArgs e)
        {
            try
            {
                _mousePosition = e.GetPosition(null);
            }
            catch
            {

            }
        }

        void txtTabName_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                this.winNewTabname.DialogResult = true;
                this.winNewTabname.Close();

            }
            else if (e.Key == Key.Escape)
            {
                this.winNewTabname.DialogResult = false;
                this.winNewTabname.Close();
            }
        }

        private void mnuSave_Click(object sender, Telerik.Windows.RadRoutedEventArgs e)
        {
            try
            {
                this.txtTabName.Text = string.Empty;
                winNewTabname.Header = "Set Name of Tab";
                winNewTabname.Top = this._mousePosition.Y;
                winNewTabname.Left = this._mousePosition.X - 200;
                winNewTabname.WindowStartupLocation = WindowStartupLocation.Manual;
                winNewTabname.ResizeMode = ResizeMode.NoResize;
                winNewTabname.Closed += new EventHandler<WindowClosedEventArgs>(winNewTabname_Closed);
                winNewTabname.ShowDialog();
            }
            catch (Exception ex)
            {
                Globals.HandleUIExceptions(ex);
            }
        }
        private void winNewTabname_Closed(object sender, WindowClosedEventArgs e)
        {
            if (e.DialogResult == true && !string.IsNullOrEmpty(this.txtTabName.Text.Trim()))
            {
                var found = from Object obj in tabNotes.Items
                            where (obj as RadTabItem).Header.ToString() == this.txtTabName.Text.Trim()
                            select obj;

                if (found.ToList().Count == 0)
                {
                    RadTabItem tabItem = new RadTabItem();
                    tabItem.Tag = this.txtTabName.Text;
                    tabItem.Header = this.txtTabName.Text;
                    tabNotes.Items.Add(tabItem);
                    this.tabNotes.SelectedIndex = tabNotes.Items.Count - 1;
                    RadContextMenu.SetContextMenu(tabItem, _ContextMenu);
                }
                else
                {

                    this.tabNotes.SelectedItem = found.ToList()[0] as RadTabItem;
                }
            }
        }
        private void winRenameTabname_Closed(object sender, WindowClosedEventArgs e)
        {
            

            ////if (e.DialogResult == true && !string.IsNullOrEmpty(this.txtTabName.Text.Trim()))
            ////{
            //    var found = from Object obj in tabNotes.Items
            //                where (obj as RadTabItem).Header.ToString() == this.txtTabName.Text.Trim()
            //                select obj;
            //    string oldtabname = found.ToString();
            //    a = this.txtTabName.Text;
            //    header
            //    (obj as RadTabItem).Header.ToString() = oldtabname;
            //    if (found.ToList().Count == 0)
            //    {
            //        RadTabItem tabItem = new RadTabItem();
            //        tabItem.Tag = this.txtTabName.Text;
            //        tabItem.Header = this.txtTabName.Text;
            //        tabNotes.Items.Add(tabItem);
            //        this.tabNotes.SelectedIndex = tabNotes.Items.Count - 1;
            //        RadContextMenu.SetContextMenu(tabItem, _ContextMenu);
            //    }
            //    else
            //    {

            //        this.tabNotes.SelectedItem = found.ToList()[0] as RadTabItem;
            //    }
            ////}
        }
        void tabNotes_SelectionChanged(object sender, RoutedEventArgs e)
        {

            if (_Selectedindex > -1)
            {
                (tabNotes.Items[_Selectedindex] as RadTabItem).Content = null;
            }
            RadTabItem tabItem = this.tabNotes.SelectedItem as RadTabItem;
            _Notes.setDimestion(_Height, _Width);
            tabItem.Content = _Notes;
            _Notes.TabName = Convert.ToString(tabItem.Header);
            _Notes.LoadNotes(Convert.ToString(tabItem.Header));
            _Selectedindex = this.tabNotes.SelectedIndex;
        }

        public TabbedNotesControl(int noOfTabs)
            : this() //Here also we can pass type for the commensts also.
        {

            RadTabItem tabItem = new RadTabItem();
            tabItem.Tag = "Comments";
            tabItem.Header = "Comments";
            tabNotes.Items.Add(tabItem);
            RadContextMenu.SetContextMenu(tabItem, _ContextMenu);
        }

        public void setDimestion(double height, double width)
        {
            _Height = this.LayoutRoot.MaxHeight = this.LayoutRoot.Height = height;
            _Width = this.LayoutRoot.MaxWidth = this.LayoutRoot.Width = width;
            this.tabNotes.SelectedIndex = 0;
        }
    }
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of abdkhlaif
abdkhlaif
Flag of Saudi Arabia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ANINDYA

ASKER

Expert AbdKhalif
Thanks for the reply.
Please see there is an error is coming .
Thanking you
Anindya
work.JPG
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ANINDYA

ASKER

Expert AbdKhalif
name option is not associated with the Items .
As you can see in the attached code.
Thanking you,
work.JPG
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Alpesh Patel
Alpesh Patel
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ANINDYA

ASKER

Expert AbdKhalif
in all cases it is taking a null value as I am just instantiating the tabcontrol and after that using your messagebox statement .
So it is not catching the value of the current tab which is clicked .
I have tried to use the this key word but failed .
can you please help me .
Thanking you,
Anindya
work.JPG
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ANINDYA

ASKER

Expert AbdKhalif
The object which is declared earlier is not accessible in the winRenameTabname_Closed()
You can see that in the intellisense.
Thanking you
work.JPG
Avatar of ANINDYA

ASKER

Expert Patel alphesh
With the TabItem object SelectedTab option is not coming.
Thanking you
Anindya
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ANINDYA

ASKER

Expert ShahanDeveloper
this is not helping.
Can you please provide some more information regarding this or any pages from where I can get some more information regarding this.
Thanking you,
anindya
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi! Anindya

Did you checked that ??
Avatar of ANINDYA

ASKER

thanks