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

Automatically setting IsBreak for Multiline RadTabStrip

1 Answer 135 Views
TabStrip
This is a migrated thread and some comments may be shown as answers.
Stephen Wright
Top achievements
Rank 2
Stephen Wright asked on 09 Dec 2008, 05:28 PM
I created an Extension method that will set the page break of a RadTabStrip for visible tabs only and then split the rows in half.  I have a situation where some of the tabs will be visible during certain page views. 

so in your code for the page_load, you would just call:
RadTabStrip1.FormatMultiLineTabs(False); 

If you have any refactorings  or improvements for this snippet, I'd be interested to see it.
Enjoy!

C#:
using Telerik.Web.UI; 
using System.Runtime.ComplierServices;  
  
public class RadTabStripExtensions  
{  
  
    [Extension()]  
    public void FormatMultiLineTabs(ref RadTabStrip tab, bool ForceMultiLine)  
    {  
        int intTabCount = 0;  
        foreach (RadTab objTab in tab.Tabs) {  
            if (objTab.Visible)  
            {  
                intTabCount += 1;  
            }  
        }  
        if (ForceMultiLine || intTabCount >= 8) // this can be changed to the line break number  
        {  
            int intTabBreakIndex = intTabCount / 2 - 1;  
            if (intTabCount % 2 == 1)  
            {  
                intTabBreakIndex += 1;  
            }  
            tab.AddTabBreakToVisibleTabIndex(intTabBreakIndex);  
        }  
    }  
  
    [Extension()]  
    public void AddTabBreakToVisibleTabIndex(ref RadTabStrip tab, int VisibleIndexBreak)  
    {  
        int intIndex = 0;  
        foreach (RadTab objTab in tab.Tabs) {  
            if (objTab.Visible)  
            {  
                if (intIndex == VisibleIndexBreak)  
                {  
                    objTab.IsBreak = true;  
                }  
                intIndex += 1;  
            }  
        }  
    }  
  
}  

VB:
Imports Telerik.Web.UI 
Imports System.Runtime.CompilerServices  
  
Public Module RadTabStripExtensions  
  
    <Extension()> _  
    Public Sub FormatMultiLineTabs(ByRef tab As RadTabStrip, ByVal ForceMultiLine As Boolean)  
        Dim intTabCount As Integer = 0  
        For Each objTab As RadTab In tab.Tabs  
            If objTab.Visible Then  
                intTabCount += 1  
            End If  
        Next  
        If ForceMultiLine OrElse intTabCount >= 8 Then 'this can be changed to the line break number 
            Dim intTabBreakIndex As Integer = intTabCount \ 2 - 1  
            If intTabCount Mod 2 = 1 Then  
                intTabBreakIndex += 1  
            End If  
            tab.AddTabBreakToVisibleTabIndex(intTabBreakIndex)  
        End If  
    End Sub  
  
    <Extension()> _  
    Public Sub AddTabBreakToVisibleTabIndex(ByRef tab As RadTabStrip, ByVal VisibleIndexBreak As Integer)  
        Dim intIndex As Integer = 0  
        For Each objTab As RadTab In tab.Tabs  
            If objTab.Visible Then  
                If intIndex = VisibleIndexBreak Then  
                    objTab.IsBreak = True  
                End If  
                intIndex += 1  
            End If  
        Next  
    End Sub  
  
End Module  

1 Answer, 1 is accepted

Sort by
0
Smitha Test
Top achievements
Rank 1
answered on 21 Oct 2009, 02:10 PM
hi

i tried to run the same snippet and its giving me errors at tab.Visible and tab.Isbreak.

Can you provide a sample.
my requirement is similar to have multi lined tabs.

Thanks again,


Tags
TabStrip
Asked by
Stephen Wright
Top achievements
Rank 2
Answers by
Smitha Test
Top achievements
Rank 1
Share this question
or