Consider the code below. When you run it, it displays a GridView of colors, with a select column. In this demo, the SelectColumn doesn't "do anything", but let's assume that it will later. Run the demo, and click the CheckBox next to the first item, which is Red. Now, click the Delete button. The row that Red is in goes away, as it should. However, the CheckBox remains, and now Orange is selected.
Orange is not the row I selected however. When Red row was deleted, I expected the Selected CheckBox to go away with it?
Orange is not the row I selected however. When Red row was deleted, I expected the Selected CheckBox to go away with it?
<UserControl x:Class="TestGridSelection.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:telerikGrid="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView" mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"> |
<Grid x:Name="LayoutRoot"> |
<StackPanel Orientation="Vertical"> |
<telerikGrid:RadGridView x:Name="radGridView" AutoGenerateColumns="True" SelectionMode="Extended"> |
<telerikGrid:RadGridView.Columns> |
<telerikGrid:GridViewSelectColumn /> |
</telerikGrid:RadGridView.Columns> |
</telerikGrid:RadGridView> |
<Button Content="Delete First Item" Click="Button_Click" /> |
</StackPanel> |
</Grid> |
</UserControl> |
using System.Collections.ObjectModel; |
using System.Windows; |
using System.Windows.Controls; |
namespace TestGridSelection |
{ |
public partial class MainPage : UserControl |
{ |
private ObservableCollection<string> _colors; |
public MainPage() |
{ |
InitializeComponent(); |
Loaded += MainPage_Loaded; |
} |
private void MainPage_Loaded(object sender, RoutedEventArgs e) |
{ |
_colors = new ObservableCollection<string> {"Red", "Orange", "Blue", "Green", "Yellow"}; |
radGridView.ItemsSource = _colors; |
} |
private void Button_Click(object sender, RoutedEventArgs e) |
{ |
_colors.RemoveAt(0); |
} |
} |
} |