Solved

How to access the tab header name?

Posted on 2010-11-09
18
1,617 Views
Last Modified: 2013-12-17
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
 1
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

0
Comment
Question by:ANINDYA
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 4
  • +1
18 Comments
 
LVL 3

Accepted Solution

by:
abdkhlaif earned 251 total points
ID: 34099583
The TabControl stores the tabs in the Controls collection:
int i = tabControl1.SelectedIndex;
MessageBox.Show(tabControl1.Controls[i].Name);

Open in new window

0
 

Author Comment

by:ANINDYA
ID: 34099665
Expert AbdKhalif
Thanks for the reply.
Please see there is an error is coming .
Thanking you
Anindya
work.JPG
0
 
LVL 3

Assisted Solution

by:abdkhlaif
abdkhlaif earned 251 total points
ID: 34099704
try Items instead of Controls
If I'm not mistaken, RadTabControl inherits from System.Windows.Controls.ItemsControl which has Items collection to hold the tabs.
int i = tabControl1.SelectedIndex;
MessageBox.Show(tabControl1.Items[i].Name);

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ANINDYA
ID: 34099771
Expert AbdKhalif
name option is not associated with the Items .
As you can see in the attached code.
Thanking you,
work.JPG
0
 
LVL 3

Assisted Solution

by:abdkhlaif
abdkhlaif earned 251 total points
ID: 34099793
I just realized that RadTabControl is not a .NET control
refer to the product documentation at
http://www.telerik.com/help/wpf/telerik.windows.controls.navigation-telerik.windows.controls.radtabcontrol_members.html

one of the control members should let you get the name of the selected tab.
try SelectedItem property:
MessageBox.Show((string)tabControl1.SelectedItem); 

Open in new window

0
 
LVL 21

Assisted Solution

by:Alpesh Patel
Alpesh Patel earned 63 total points
ID: 34101590
Hi,

Get the SelectedTab in TabItem object and get text using TabItem.Text
0
 

Author Comment

by:ANINDYA
ID: 34101730
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
0
 
LVL 3

Assisted Solution

by:abdkhlaif
abdkhlaif earned 251 total points
ID: 34101829
The tab control is already created & initialized in the InitializeComponent() method, you shouldn't create another tab control inside winRenameTabname_Closed()
so you need to replace "tabControl1" with the correct object name
0
 

Author Comment

by:ANINDYA
ID: 34102783
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
0
 

Author Comment

by:ANINDYA
ID: 34102799
Expert Patel alphesh
With the TabItem object SelectedTab option is not coming.
Thanking you
Anindya
0
 
LVL 19

Assisted Solution

by:Shahan Ayyub
Shahan Ayyub earned 186 total points
ID: 34127375
Hi!

Its not a simple TabControl its custom Control so I can not tell you directly as my internet connection is very slow to download control and test it.

Check this: (Code for rename menu)

RadTabItem item = this.tabNotes.SelectedItem as RadTabItem;
String NameOfTab = item.Header;


Is this helpful ??
0
 

Author Comment

by:ANINDYA
ID: 34129923
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
0
 
LVL 19

Assisted Solution

by:Shahan Ayyub
Shahan Ayyub earned 186 total points
ID: 34130982
What did you get ?? when used this code???
0
 
LVL 19

Assisted Solution

by:Shahan Ayyub
Shahan Ayyub earned 186 total points
ID: 34132585
Did you check this as well:

RadTabItem item = this.tabNotes.SelectedItem as RadTabItem;
object NameOfTab = item.Header;


You need to check this properties as well from the below link:
http://www.telerik.com/help/wpf/telerik.windows.controls.navigation-telerik.windows.controls.radtabcontrol_properties.html

Items property its a collection and find the current selected tab and search for Header property.
Header property


In this piece of code:

Dim index As Integer
Dim value As RadTabItem
value = tabNotes.Item(index)

Find Header Property under "value".
0
 
LVL 19

Expert Comment

by:Shahan Ayyub
ID: 34279517
Hi! Anindya

Did you checked that ??
0
 

Author Closing Comment

by:ANINDYA
ID: 34288902
thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Vb.net threads keep increasing 2 49
Code works but breaks when I add one section 4 29
Header Font Size in Grid View 6 24
How to set focus on a dynamic control 18 20
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question