Now, FlexGrid provides a fantastic method called Select, which enables us to select a Cell/Row/CellRange, etc., depending on the Overload we choose to use and the SelectionMode property of C1FlexGrid. For example, if the SelectionMode property is set to "Cell" and we provide a CellRange as the parameter to the Select method, it would select only the first Cell in the CellRange.
So getting to the point: we wish to select an entire row when the Window is displayed and also be able to navigate through rows using the arrows keys without having to touch the mouse. Sounds pretty cool, doesn't it?
Setting the SelectionMode
First of all, we set the SelectionMode property of FlexGrid to "Row" so that we're able to select the entire row and not just a single cell.
<c1:C1FlexGrid x:Name="c1FlexGrid1" HorizontalAlignment="Left" Margin="12,12,0,0" Loaded="c1FlexGrid1_Loaded" SelectionMode="Row" Height="350" AutoGenerateColumns="True" VerticalAlignment="Top" />
Selecting the Row
Now, we use the Select method to select a particular row (eg 6th row).
c1FlexGrid1.Select(5, 0, 5, c1FlexGrid1.Columns.Count - 1, true);
What if FlexGrid contains 100s of records, and a vertical scrollbar is displayed, and you wish to select the 20th row and also scroll it into view? For this we need to handle the Loaded event of FlexGrid and then call the Select method.
private void c1FlexGrid1_Loaded(object sender, RoutedEventArgs e)
c1FlexGrid1.Select(16, 0, 16, c1FlexGrid1.Columns.Count - 1, true);
Notice that we've called the Focus method as well. This sets focus on FlexGrid so that we can navigate through the rows using the keyboard without having to click inside the grid.