Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
914
What's the best way to switch between CellClickAction RowSelect and CellSelect
posted

I have a grid where the 3rd column is a header text with the 1st two columns used for GroupBy so I can visualize them as nodes. This use is a conversion from a C1 FlexGrid. The C1 grid had selection modes of ListBox (similar to RowSelect) and Cell (similar to CellSelect). In the C1 grid, I only had to deal with the heading column for ListBox selection while all other columns where Cell selection; in the UltraWinGrid I am also dealing with clicking on GroupBy row. The C1 grid had a BeforeMouseDown event where I could determine the column of the mouse and swich the selection mode as necessary, and this event ocurred before the selection mode was in place for the mouse down action.

The UltraWinGrid dos not have a BeforeMouseDown event. I am locating the mouse GroupBy row or column in the MouseDown event; but this event appears too late to be able to switch between selection modes properly. Currently I am keeping the grid in RowSelection mode and switching it to CellSelection mode in the MouseDown event if the mousedown is on a column greater than my heading column. I then restore the grid to RowSelection in the MouseUp event. I would prefer to just set it to whatever was needed in a single event.

Is their a better way to do this? Or can you folks consider adding a BeforeMouseDown event that is raised beofre handling the current CellSelection mode?

For what its worth, here is an approximation of the code I am using.

    Private Sub ugFlowSheet_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ugFlowSheet.MouseDown
        Dim ugUIElement As UIElement = ugFlowSheet.DisplayLayout.UIElement.ElementFromPoint(omdMouse.pt)
        Dim ugRow As UltraGridRow = ugUIElement.GetContext(GetType(UltraGridGroupByRow))
        If Not ugRow Is Nothing Then Exit Sub  ' Keep RowSelect on groupby rows
        ' Retrieve the Column from the UIElement
        Dim ugColumn As UltraGridColumn = ugUIElement.GetContext(GetType(UltraGridColumn))
        ' If not a column, then exit
        If (ugColumn Is Nothing) Then Exit Sub ' Not a column; Keep RowSelect
        ' Keep extended selection on GroupBy rows or finding header column
        If (ugColumn.Index <= COL_HEAD) Then Exit Sub
        With ugFlowSheet.DisplayLayout
            ' If we just switched from extended select to cell select, deselect any selected rows
            If (.Override.CellClickAction = CellClickAction.RowSelect) Then
                Dim oSelected As Selected = ugFlowSheet.Selected
                If (oSelected.Rows.Count > 0) Then
                    oSelected.Rows.Clear()
                End If
            End If
            .Override.CellClickAction = CellClickAction.CellSelect  ' We do not go into edit mode
            .Override.SelectTypeCell = SelectType.Single
            .Override.SelectTypeRow = SelectType.None
            .Override.SelectTypeGroupByRow = SelectType.None    ' Keeps GroupBy rows (group, subgroup) from selecting
        End With
    End Sub

    Private Sub ugFlowSheet_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ugFlowSheet.MouseUp
        With ugFlowSheet.DisplayLayout
            If (.Override.CellClickAction = CellClickAction.CellSelect) Then
                .Override.CellClickAction = CellClickAction.RowSelect  ' We do not go into edit mode
                .Override.SelectTypeCell = SelectType.Extended
                .Override.SelectTypeRow = SelectType.Extended
                .Override.SelectTypeGroupByRow = SelectType.Extended    ' Keeps GroupBy rows (group, subgroup) from selecting
            End If
        End With
    End Sub