Most grid controls allow users to select parts of the data using the mouse and the keyboard. FlexGrid supports selection through the SelectionMode property. This property determines how the cell or rows are selected in grid.
FlexGrid provides a series of properties as a part of Selection API that work with data items. These properties are:
All these properties provide more flexibility in manipulating the selected items at runtime and further customize your application behavior.
The following image shows how Selected Index displays the index of the selected row while the SelectedItem and SelectedItems option display the data items and the collection of data items for the selected row(s), respectively.
To understand how to use these properties, use the following code. In this example, we have used a class named Persons to get the data for FlexGrid.
XAML |
Copy Code
|
---|---|
<c1:FlexGrid x:Name="grid" ItemsSource="{Binding Persons}" SelectedItem="{Binding SelectedPerson, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" SelectedIndex="{Binding SelectedPersonId,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" SelectionChanged="FlexGridSelectionChanged" SelectionMode="CellRange" /> <StackPanel Grid.Column="1"> <StackPanel Orientation="Horizontal" Margin="0,10,0,0"> <TextBlock Text="Selected Index: " FontWeight="Bold"/> <TextBlock Text="{Binding SelectedPersonId}"/> </StackPanel> <TextBlock Text="Selected Item:" FontWeight="Bold" Margin="0,20,0,0"/> <StackPanel Orientation="Horizontal"> <TextBlock Text="Id: " FontWeight="Bold"/> <TextBlock Text="{Binding SelectedPerson.Id, UpdateSourceTrigger=Default}"/> <TextBlock Text="Name: " FontWeight="Bold" Margin="10,0,0,0"/> <TextBlock Text="{Binding SelectedPerson.Name, UpdateSourceTrigger=PropertyChanged}"/> <TextBlock Text="Age: " FontWeight="Bold" Margin="10,0,0,0"/> <TextBlock Text="{Binding SelectedPerson.Age, UpdateSourceTrigger=PropertyChanged}"/> </StackPanel> <TextBlock Text="Selected Items:" FontWeight="Bold" Margin="0,20,0,0"/> <c1:FlexGrid ItemsSource="{Binding SelectedPersons, UpdateSourceTrigger=PropertyChanged}"/> </StackPanel> |