Select row if row header is clicked

Apr 8, 2009 at 10:11 PM
I want to emulate an Excel behavior where when you click the row header, the row is selected.  I first tried switching to SelectionMode=SelectionMode.Row; however, there is no way to know when to turn if off.

After several hours of putzing around, I found that if I do a SelectRow inside a MouseDown handler if the header row is the object, works almost the way I want.  The only thing I am missing is being able to select several rows by holding the left mouse button down and dragging the mouse up or down.  Anyone have a suggestion on how to do this?
Apr 9, 2009 at 10:20 AM
Selection controller is the direction to look at
Apr 12, 2009 at 5:35 PM
Thanks again for your help.
I made column 0 selectable. Not the best solution but it works for now. The paste logic in the program ignores column 0.
I then modified SelectionBase.cs\OnCellGotFocus(ChangeActivePositionEventArgs e)
Changing SelectCell(m_activePosition, true)
//Modified to select entire row if row header is clicked. JHM 4/10/2009
If (m_activePosition.Column == 0)
// Select the row
SelectRow(m_activePosition.Row, true);
//Select the cell
SelectCell(m_activePosition, true);
Now it selects rows if the cell in column 0 is clicked.
In order to get the rows selected when draggin the mouse down, I modified GridVirtual.cs\OnMouseSelectionChange(EventArgs e)
Adding code to extend l_MouseRange as follows:
//Change the range to be full rows if the range contains column 0) JHM 4/10/2009
if (l_mouseRange.ContainsColumn(0))
int startRow = Min(l_MouseRange.Start.Row, l_MouseRange.End.Row);
int endRow = Max(l_MouseRange.Start.Row, l_MouseRange.End.Row);
l_mouseRange = new Range(startRow, 0, endRow, Columns.Count - 1);
I still have on issue left. When selecting multiple rows or cells using the Control key, the rows or cells appear in the order clicked when I retrieve the selected range.
RangeRegion rangereg = grid.Selection.GetSelectionRegion()
PositionCollection cellsToCopy = rangereg.GetCellsPositions();
To correct this, I attempted to use the Sort method.
Which throws and error - Failed to compare two elements in the array. It looks like its basic assumption is that the array is an array of ints not an array of Positions.
I apologize but I don't understand the syntax of the first overload ... cellsToCopy.Sort(Comparison<type> comparison). Would you please provide an example?