This is a migrated thread and some comments may be shown as answers.

tricky binding question

2 Answers 113 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Randy Hompesch
Top achievements
Rank 1
Randy Hompesch asked on 23 Nov 2016, 03:16 PM

Hi,

Below is an excerpt of some xaml I am using. The important thing to notice is that I have a listbox of checkboxes associated with each grid row.
How do I bind the all the checkboxes that I want checked for selected gridview item?

Thanks ... Ed

 

 

01.<telerik:RadGridView  x:Name="ssSamples" Grid.Row="0" Grid.Column="0"
02.                    AutoGenerateColumns="False"  IsReadOnly="True"
03.                     ItemsSource="{Binding Samples}"
04.                     SelectedItem="{Binding SelectedRow}"
05.                     MaxHeight="500" RowIndicatorVisibility="Visible"
06.                             >
07.    <telerik:RadGridView.Columns>
08.        <telerik:GridViewToggleRowDetailsColumn />
09.        <telerik:GridViewDataColumn Width="auto" Header="Sample Key" DataMemberBinding="{Binding Sample_Key}"/>
10.        <telerik:GridViewDataColumn Width="auto" Header="Client Sample Id" DataMemberBinding="{Binding ClientSampleID}"/>
11.        <telerik:GridViewDataColumn Width="auto" Header="Arrival" DataMemberBinding="{Binding Arrival}"/>
12.        <telerik:GridViewDataColumn Width="*" Header="Status" DataMemberBinding="{Binding Status}"/>
13.    </telerik:RadGridView.Columns>
14.    <telerik:RadGridView.RowDetailsTemplate>
15.        <DataTemplate>
16.            <Grid Width="Auto" HorizontalAlignment="Stretch">
17.                <Grid.RowDefinitions>
18.                    <RowDefinition />
19.                    <RowDefinition />
20.                </Grid.RowDefinitions>
21.                <Grid.ColumnDefinitions>
22.                    <ColumnDefinition Width="Auto" />
23.                    <ColumnDefinition Width="Auto" />
24.                    <ColumnDefinition Width="Auto" />
25.                    <ColumnDefinition Width="Auto" />
26.                </Grid.ColumnDefinitions>
27. 
28.                <Label Content="Associated Techniques:" Grid.Row="0" Grid.Column="2"
29.                       HorizontalAlignment="Left" HorizontalContentAlignment="Left"  Width="350" Height="auto"/>
30.                <telerik:RadListBox x:Name="lstTechniques" Grid.Row="1" Grid.Column="2" MaxHeight="210"
31.                    SelectionMode="Extended"
32.                    ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor,
33.                                    AncestorType={x:Type UserControl} },
34.                                    Path=DataContext.Techniques}"
35.                                        >
36.                    <telerik:RadListBox.ItemTemplate>
37.                        <DataTemplate >
38.                            <CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay}"
39.                                                        Content="{Binding TechniqueName}"/>
40.                        </DataTemplate>
41.                    </telerik:RadListBox.ItemTemplate>
42.                </telerik:RadListBox>
43.            </Grid>
44. 
45.        </DataTemplate>
46.    </telerik:RadGridView.RowDetailsTemplate>
47.</telerik:RadGridView>

2 Answers, 1 is accepted

Sort by
0
Accepted
Dilyan Traykov
Telerik team
answered on 24 Nov 2016, 03:18 PM
Hello,

The DataContext of each RowDetails element is its parent row's bound data item. Thus, provided the objects inside your Samples collection have a Techniques collection property, where each Technique has its own IsSelected and TechniqueName properties, the following code should result in the expected result.

<telerik:RadListBox x:Name="lstTechniques" Grid.Row="1" Grid.Column="2" MaxHeight="210"
SelectionMode="Extended"
ItemsSource="{Binding Techniques}">
    <telerik:RadListBox.ItemTemplate>
        <DataTemplate >
            <CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay}"
                                  Content="{Binding TechniqueName}"/>
        </DataTemplate>
    </telerik:RadListBox.ItemTemplate>
</telerik:RadListBox>

If you, however, wish to bind your RadListBox's ItemsSource to a Techniques property in your view model, you will need to specify the Source of this binding, similarly to:

<telerik:RadListBox x:Name="lstTechniques" Grid.Row="1" Grid.Column="2" MaxHeight="210"
                    SelectionMode="Extended"
                    ItemsSource="{Binding Techniques, Source={StaticResource MyViewModel}}">
    <telerik:RadListBox.ItemTemplate>
        <DataTemplate >
            <CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay}"
              Content="{Binding TechniqueName}"/>
        </DataTemplate>
    </telerik:RadListBox.ItemTemplate>
</telerik:RadListBox>

For your reference, I'm attaching a sample project based on your scenario.

I hope you find this information helpful. Please let me know if you need any further assistance on the matter.

Regards,
Dilyan Traykov
Telerik by Progress
Telerik UI for WPF is ready for Visual Studio 2017 RC! Learn more.
0
Randy Hompesch
Top achievements
Rank 1
answered on 26 Nov 2016, 01:18 PM

Got it! Thanks.

 

Tags
GridView
Asked by
Randy Hompesch
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Randy Hompesch
Top achievements
Rank 1
Share this question
or