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
Hi,
What version of the grid are you using? In the latest version, I am pretty sure that there is a CellClickAction property on the column. So you can set it on each column and you don't have to handle any events at all.
Thanks Mike. I am using 9.1. I checked and there is a CellClickAction property on the UltraGridColumn object. So I removed the code from the MouseDown and MouseUp events. In the grid initialization, I am setting the DisplayLayout properties as follows:
.Override.SelectTypeCell = SelectType.Single.Override.SelectTypeRow = SelectType.Extended.Override.SelectTypeGroupByRow = SelectType.Extended
Then in my procedure that finishes up the layout styling, I added the following:
For Each ugCol In .Columns Select Case ugCol.Index Case COL_GROUP To COL_HEAD ugCol.CellClickAction = CellClickAction.RowSelect ' We go into row mode Case Else ugCol.CellClickAction = CellClickAction.CellSelect ' We do not go into edit mode End SelectNext
This then works exactly as what is needed. If I click into any cell after the heading column, it only selects the single cell and it does not extend the selection on dragging the mouse. But if I click on any heading cell or either of the two GroupBy rows, it allows me to multiselect the rows I drag over.
Thanks again for the quick come back.