I have a radcombobox that has a list of checkboxes that has multiselect.
-- template for the checkbox
<UserControl.Resources> <DataTemplate x:Key="MultiSelectComboTemplate"> <Grid> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition/> </Grid.RowDefinitions> <StackPanel Orientation="Horizontal"> <CheckBox x:Name="checkbox" IsChecked="{Binding IsSelected}" Command="{Binding ElementName=_cboTeams, Path=DataContext.SelectCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type telerik:RadComboBox}}}"/> <TextBlock Text="{Binding Name}" Margin="5 0 0 0"/> </StackPanel> </Grid> </DataTemplate> <CollectionViewSource x:Key="teams" Source="{Binding Teams}"/> </UserControl.Resources>
-- radcombobox <telerik:RadComboBox x:Name="_cboTeams" Grid.Row="1" Grid.Column="2" Margin="5 0 5 0" Width="120" SelectedValuePath="Id" ItemsSource="{Binding Teams}" AllowMultipleSelection="True" ItemTemplate="{StaticResource MultiSelectComboTemplate}" DropDownClosed="_cboTeams_DropDownClosed" Command="{Binding ElementName=_cboTeams, Path=DataContext.SelectCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Self}}"> </telerik:RadComboBox>
Two questions.
1. I find that I need to get the most current item selected. With that said, how do I get the most current row(either by Id or by Index)
2. Second, my radcombobox has two types of "events" i need to worry about. One is when the row is clicked and highlighted and another one when user clicks the checkbox itself. If I click the row , I manually search for the item on the Viewmodel and mark the item checked to check the checkbox of that row. My issue is, if the user clicks the checkbox, I can trigger the command of the viewmodel and I will pass the s
private void OnSelect(object sender) { if (sender is CheckBox) { var obj = sender as CheckBox; var team = (LabeledValueCheckBox)obj.DataContext; if (team.IsSelected) { if (team.Id == 0) { foreach (var t in this.Teams) { t.IsSelected = true; } } } else { foreach (var t in this.Teams) { t.IsSelected = false; } } } else { var obj = sender as RadComboBox; var contxt = (AddFirmViewModel)obj.DataContext; var selectedTeams = obj.SelectedItems; if(obj.SelectedItems == null) { foreach(LabeledValueCheckBox t in obj.ItemsSource) { if (t.IsSelected) { selectedTeams.Add(t); } } } if (selectedTeams != null) { if (selectedTeams.Contains(contxt.Teams[0]))// select all { foreach (var t in contxt.Teams) { t.IsSelected = true; selectedTeams.Add(t); } } else { foreach (var t in contxt.Teams) { var exists = selectedTeams.Contains(t); if (exists) { t.IsSelected = true; } else { t.IsSelected = false; } } } } } SelectPressed?.Invoke(this, new EventArgs()); }
