Unplanned
Last Updated: 29 Aug 2023 11:51 by ADMIN
Ken
Created on: 29 Aug 2023 10:28
Category: Spreadsheet
Type: Feature Request
0
RadSpreadsheet: Add a context menu option for resizing a column with a fixed width like MS Excel

The resize option available in MS Excel is:

1 comment
ADMIN
Dess | Tech Support Engineer, Principal
Posted on: 29 Aug 2023 11:51

Hello, Ken,

Thank you for bringing this reasonable request to our attention.

I have invested some time to create a sample code snippet how such kind of functionality can be implemented adopting the functionality coming from the RadSpreadProcessing library: 

    Sub New()
        InitializeComponent()

        AddHandler Me.RadSpreadsheet1.SpreadsheetElement.ContextMenuShowing, AddressOf SpreadsheetElement_ContextMenuShowing

    End Sub

    Dim myMenuItem As New RadMenuItem("My item")
    Private Sub SpreadsheetElement_ContextMenuShowing(sender As Object, e As SpreadsheetContextMenuOpeningEventArgs)
        Dim hideItemText = Telerik.WinForms.Spreadsheet.LocalizationManager.CurrentProvider.GetLocalizedString("Spreadsheet_Context_Menu_Hide_Columns")
        Dim isHeader As Boolean = False
        For Each item As RadItem In e.Menu.Items
            Dim menuItem As RadMenuItem = TryCast(item, RadMenuItem)
            If menuItem Is Nothing Then
                Continue For
            End If
            If menuItem.Text = hideItemText AndAlso menuItem.Visibility = ElementVisibility.Visible Then
                isHeader = True
                Exit For
            End If
        Next


        If isHeader AndAlso Not e.Menu.Items.Contains(myMenuItem) Then
            myMenuItem = New RadMenuItem("My item")
            AddHandler myMenuItem.Click, AddressOf myMenuItem_Click
            e.Menu.Items.Add(myMenuItem)
        ElseIf isHeader = False AndAlso e.Menu.Items.Contains(myMenuItem) Then
            e.Menu.Items.Remove(myMenuItem)
        End If
    End Sub

    Private Sub myMenuItem_Click(sender As Object, e As EventArgs)
        Dim pixelWidthToExcelWidth As Double = UnitHelper.PixelWidthToExcelColumnWidth(Me.RadSpreadsheet1.Workbook, 200)
        Dim newColumnWidth As ColumnWidth = New ColumnWidth(pixelWidthToExcelWidth, isCustom:=True)
        Me.RadSpreadsheet1.ActiveWorksheetEditor.Selection.Columns.SetWidth(newColumnWidth)
    End Sub

The achieved result is illustrated below:

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.