This is a migrated thread and some comments may be shown as answers.

In-place Tabitem.Text editing

3 Answers 61 Views
Tabstrip (obsolete as of Q2 2010)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jorge Delgado-Lopez
Top achievements
Rank 1
Jorge Delgado-Lopez asked on 21 May 2007, 06:06 PM
Hi,

I wonder how I could inplace edit the Text of a tabitem. Same thought as the TreeView and with LabelEdit = true.

Thanks,
- jorge

3 Answers, 1 is accepted

Sort by
0
Boyko Markov
Telerik team
answered on 22 May 2007, 05:18 PM
Hello Jorge Delegado,

We do not support that feature built-in our RadTabStrip but I could propose a sample solution which will demonstrate how to implement in-place editing of TabItems. Here are the steps:

1) Create a new instance of RadTabStrip and add a few items to it.
2) Create a new class, lets say AssociatedTextBox, and place the following code in it:
 
public class AssociatedTextBox : RadTextBox 
        { 
            private TabItem associatedItem; 
 
            public TabItem AssociatedItem 
            { 
                get 
                { 
                    return this.associatedItem; 
                } 
                set 
                { 
                    this.associatedItem = value; 
                } 
            } 
 
 
            public AssociatedTextBox(TabItem item) 
            { 
                this.associatedItem = item; 
            } 
 
        } 

 
3) Place the following code in the form constructor:
 
textBox = new AssociatedTextBox(null); 
this.radTabStrip1.Controls.Add(this.textBox); 
this.textBox.Visible = false
this.textBox.KeyDown += new KeyEventHandler(textBox_KeyDown); 

 
As you could see here we initialize our textbox and we add it to RadTabStrip's controls collection.
Now we should handle the textBox's KeyDown event and RadTabStrip's MouseDoubleClick's event.

4) Place the following code in MouseDoubleClick handler of RadTabStrip:
 
private void radTabStrip1_MouseDoubleClick(object sender, MouseEventArgs e) 
        { 
            foreach (TabItem item in this.radTabStrip1.Items) 
            { 
                if (item.Bounds.Contains(e.Location)) 
                { 
                    this.textBox.AssociatedItem = item; 
                    this.textBox.Text = item.Text; 
                    this.textBox.Bounds = item.Bounds; 
                    this.textBox.Visible = true
 
                    return
                } 
            } 
        } 


5) The last step is to write some code which will update the text in the tabItem or cancel the editing.
 
void textBox_KeyDown(object sender, KeyEventArgs e) 
        { 
            if (e.KeyData == Keys.Enter) 
            { 
                if (this.textBox.AssociatedItem != null
                { 
                    this.textBox.AssociatedItem.Text = this.textBox.Text; 
                    this.textBox.Hide(); 
                } 
            } 
 
            if (e.KeyData == Keys.Escape) 
            { 
                this.textBox.Hide(); 
                this.textBox.Text = ""
            } 
        } 

I hope that this helps.

 
Greetings,
Ray
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
kdev
Top achievements
Rank 1
answered on 07 Nov 2007, 05:28 PM

Hi,
I notice that in Q2 SP1 we can edit the TabItem text In-Place. (Version Notes).
how can I enable this feature ? is there a new property or method? ...
Thanks,
kort 
0
Mike
Telerik team
answered on 08 Nov 2007, 04:48 PM
Thank you for asking this, Kort.

In order to turn it this feature you should set the AllowEdit property of RadTabStrip to true. Since we have just implemented the "F2" key as a trigger for item editing (it works only when the TabStrip is focused), you may also need to call the BeginEdit / EndEdit methods of the TabStripElement to edit the selected TabItem.

I have prepared an example that demonstrates this approach for you.

Let us know if you have other questions.
 
 
Greetings,
Mike
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Tabstrip (obsolete as of Q2 2010)
Asked by
Jorge Delgado-Lopez
Top achievements
Rank 1
Answers by
Boyko Markov
Telerik team
kdev
Top achievements
Rank 1
Mike
Telerik team
Share this question
or