Changing selection direction

2 posts, 0 answers
  1. Bernhard
    Bernhard avatar
    3 posts
    Member since:
    Jul 2013

    Posted 20 May Link to this post

    Hello.

    I'm using VirtualGrid as a calendar with months as columns and days as rows. The default selection mode is row-wise. I'd like to change it column-wise.

    Let's say I select a range in the grid from 1st of feb (rowindex 0, columnindex 1) to 2nd of march (row 1, col 2). The selected cells are (0,1) (0,2) (1,1) (1,2). In my grid the selected cells should be (0,1) to (0,28) (1,1) (1,2).

    I tried to implement the SelectionChanging event but I didn't got it working. Neither the actual selection is canceled nor the new selection is executed.

        Private Sub RadVirtualGrid1_SelectionChanging(sender As Object, e As VirtualGridSelectionChangingEventArgs) Handles RadVirtualGrid1.SelectionChanging

            If e.SelectionAction = VirtualGridSelectionAction.ExtendSelection Then
                If RadVirtualGrid1.Selection.SelectedRegion.Left <> RadVirtualGrid1.Selection.SelectedRegion.Right Then
                    e.Cancel = True
                    Dim first_top As Integer = RadVirtualGrid1.Selection.SelectedRegion.Top
                    Dim last_bottom As Integer = RadVirtualGrid1.Selection.SelectedRegion.Bottom

                    Dim curr_top As Integer = first_top
                    Dim curr_bottom = ROW_OFFSET + 31
                    For col As Integer = RadVirtualGrid1.Selection.SelectedRegion.Left To RadVirtualGrid1.Selection.SelectedRegion.Right
                        RadVirtualGrid1.Selection.BeginSelection(curr_top, col, RadVirtualGrid1.Selection.SelectedRegion.ViewInfo, True)
                        RadVirtualGrid1.Selection.ExtendCurrentRegion(curr_bottom, col)

                        curr_top = ROW_OFFSET
                        If col = RadVirtualGrid1.Selection.SelectedRegion.Right - 1 Then
                            curr_bottom = last_bottom
                        End If
                    Next

                End If
            End If

        End Sub

    Best regards,

    Ronald

  2. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 25 May Link to this post

    Hi Bernard,

    Thank you for writing.

    First, you should enable the MultiSelect and set the SelectionMode to CellSelect:
    Me.radVirtualGrid1.MultiSelect = True
    Me.radVirtualGrid1.SelectionMode = VirtualGridSelectionMode.CellSelect

    Then you can use the SelectionChanged event to select the entire column:
    Private Sub RadVirtualGrid1_SelectionChanged(ByVal sender As Object, ByVal e As EventArgs)
        RemoveHandler Me.radVirtualGrid1.SelectionChanged, AddressOf RadVirtualGrid1_SelectionChanged
        radVirtualGrid1.VirtualGridElement.Selection.BeginSelection(0, radVirtualGrid1.CurrentCell.ColumnIndex, radVirtualGrid1.MasterViewInfo, False)
        radVirtualGrid1.VirtualGridElement.Selection.ExtendCurrentRegion(radVirtualGrid1.RowCount, radVirtualGrid1.CurrentCell.ColumnIndex)
        AddHandler Me.radVirtualGrid1.SelectionChanged, AddressOf RadVirtualGrid1_SelectionChanged
     
    End Sub


    The attached video show the result on my side. 

    I hope this will be useful. 

    Regards,
    Dimitar
    Telerik
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top