private void QueryActivities() |
{ |
QueryClient qc = new QueryClient("BasicHttpBinding_IQuery"); |
QueryFilter filter = new QueryFilter(); |
filter.CallForService = cfsCB; |
filter.NCICReturn = false; |
filter.RMSQuery = false; |
filter.DLSwipe = false; |
filter.Booking = false; |
filter.ArrestReport = reportCB; |
filter.CustodyReport = reportCB; |
filter.CitationReport = reportCB; |
filter.FieldInterviewReport = reportCB; |
filter.IncidentReport = reportCB; |
filter.IncidentSupplimentReport = reportCB; |
var actresult = qc.GetFilteredActivityIndex(filter); |
this.actGridView.ItemsSource = actresult; |
} |
//placed in Window initialization |
this.actGridView.Loaded += (o, e) => |
{ |
this.actGridView.SelectedItems.CollectionChanged += new NotifyCollectionChangedEventHandler(SelectedItems_CollectionChanged); |
}; |
void SelectedItems_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) |
{ |
if (e.Action == NotifyCollectionChangedAction.Add) |
{ |
var person = e.NewItems[0] as People; |
//PeopleView.SelectedPeople.Add(person); //writes selected values to selected people when row is selected. |
myID = person.uniqueID; |
} |
} |
<Grid x:Name="LayoutRoot"> <StackPanel x:Name="spQuestions" Orientation="Vertical" Grid.Column="1" Grid.Row="8" Grid.ColumnSpan="3" HorizontalAlignment="Left"> </StackPanel> </Grid> |
RadGridView gridView = new RadGridView(); gridView.ItemsSource = question.Answers; gridView.AutoGenerateColumns = false; gridView.ScrollMode = Telerik.Windows.Controls.GridView.ScrollUpdateMode.RealTime;gridView.ShowGroupPanel = false; spQuestions.Children.Add(gridView); |
I recently downloaded the WPF Trial package 2010 Q2 SP2 since we’ll probably be using that at work. I did with a separate branch of our code that is currently in development and is currently using a WPF Toolkit grid with row details which the customers don’t really like since they want a nice looking “tree grid”.
I very quickly replaced the grid with a RadGridView using a HierarchicalChildTemplate and got it up and running very nice in less than 30 minutes. We showed it to our customers to show them what might be possible and they got really impressed both by the looks, the child level functionality and especially the grouping/filtering/sorting that existed out of the box.
When showing/testing it we only used already existing data and didn’t change the data.
So I happily started yesterday with changing a couple of more grids and then started to run the application and immediately got stuck with rows not getting unselected after being edited by code.
After spending almost a day without understanding what I do wrong even with the smallest example without hierarchy I thought I should try to ask for an explanation here.
What I have in my small sample app is an Order entity that implements INotifyPropertyChanged for its properties.
A PresentationModel class also implementing INotifyPropertyChanged that pretty much consists of an ObservableCollection<Order>.
In the code behind of the xaml window I set the DataContext of the window to a new instance of the PresentationModel and create a list with four orders (with different data that makes both the Equals and GetHashCode return different values for each order).
Then I create a RadGridView in XAML and bind it like this:
<telerik:RadGridView x:Name="orderGrid" ItemsSource="{Binding Orders}"/>
I also added a button to the XAML file where I loop through the SelectedItems like this:
foreach (Order order in orderGrid.SelectedItems)
{
order.Customer = "Kalle";
}
When run the application select a row and press the button the Customer column gets nicely updated to Kalle, but when I select another row the first one stays selected and I can’t find any way to get it out of the SelectedItems collection. If I Ctrl-click the row to unselect it and select another row it looks like just the other row is selected, but the SelectedItems still contains also the changed row no matter what I do. If I select yet another row and press the button also both of the rows gets set to Kalle and then both are stuck selected.
I guess I must be doing something completely stupid or missing something obvious because I don’t find anyone else on the forums that are experiencing this and binding to an ObservableCollection with custom entities and changing data by code can’t be an uncommon scenario.
<Grid Name="SceneCarouselGrid"> |
<Grid.Resources> |
<DataTemplate DataType="{x:Type local:Scene}"> |
<Grid Width="285" Height="315"> |
<StackPanel> |
<Grid Name="ItemGrid"> |
<Grid.RowDefinitions> |
<RowDefinition Height="30" /> |
<RowDefinition Height="60*" /> |
</Grid.RowDefinitions> |
<Label Grid.Row="0" Content="{Binding Path=Title}" HorizontalAlignment="Center" HorizontalContentAlignment="Center" VerticalAlignment="Center" VerticalContentAlignment="Center" Margin="0" Name="SceneLabel" FontFamily="HelveticaNeue" FontWeight="Bold" FontSize="15" Background="#00000000" Foreground="White" /> |
<Border Grid.Row="1" x:Name="CarouselItemMainBorder" Margin="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MinHeight="285" MinWidth="285" BorderThickness="3"> |
<Border.BorderBrush> |
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> |
<GradientStop Color="#FFE8A13C" Offset="0" /> |
<GradientStop Color="Transparent" Offset="1" /> |
</LinearGradientBrush> |
</Border.BorderBrush> |
<Border.Background> |
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> |
<GradientStop Color="#FFC1DCFF" Offset="0"/> |
<GradientStop Color="#FF7EB8F8" Offset="1"/> |
</LinearGradientBrush> |
</Border.Background> |
<Image Source="{Binding Path=Image}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Height="285" Width="285" /> |
</Border> |
</Grid> |
</StackPanel> |
</Grid> |
</DataTemplate> |
</Grid.Resources> |