2

I have been struggling for this issue for the last one month. Please Help me out. I have a WPF datagrid (datagrid1) in which i am populating a datatable its working fine, in the same UI i have another WPF datagrid (datagrid2) which is to be populated as the mulitple rows selection from the first datagrid1 , how can we do this? Main problem is i want to bind the rows which are selected (multiple) how do i do? Help Me out please.

<DataGrid Name="dataGridSearchResults" 
          FontWeight="Normal" AutoGenerateColumns="False" 
          IsReadOnly="True" 
          ItemsSource="{Binding SearchResults,Mode=Default}" 
          SelectedIndex="{Binding SelectedIndexSearchResults}" 
          SelectionMode="Single" Margin="1,0,0,0" 
          Height="174" GridLinesVisibility="None" >
   <DataGrid.Columns>
        <DataGridTextColumn Header="RFC ID" Binding="{Binding RFCID}"></DataGridTextColumn>
        <DataGridTextColumn Header="RFC Title" Binding="{Binding RFCTitle}"></DataGridTextColumn>
        <DataGridTextColumn Header="RFC Revision" Binding="{Binding RFCRevision}"></DataGridTextColumn>
        </DataGrid.Columns>
</DataGrid>`

Thanks NallsKarthi

Bruno
  • 1,944
  • 13
  • 22
nallskarthi
  • 281
  • 1
  • 8
  • 19

1 Answers1

3

You just have to bind the ItemsSource property of your second datagrid to the SelectedItems property of your first datagrid :

<WPFToolkit:Datagrid x:Name="dg1" ItemsSource="{Binding MySourceFromDatabase}" SelectionMode="Extended"/>

<WPFToolkit:Datagrid x:Name="dg2" ItemsSource="{Binding ElementName=dg1,Path=SelectedItems}" />
Bruno
  • 1,944
  • 13
  • 22
  • Thanks for you reply Bruno, But what i want is that how do you bind the selected Rows from the first datagrid1? – nallskarthi Apr 26 '11 at 08:58
  • you said that populating your first datagrid was working fine, so I assumed that the blocking point was how to set the second datagrid with selected elements of the first one... Did I misunderstood something ? If it's the casen then, I suggest you to post some code sample in order to clarify things. – Bruno Apr 26 '11 at 09:45
  • Wats my exact blocking is that i am unable to bind the selected Rows in Viewmodel , now i have done with single row selection using selctionmode='single' but even after i changed to 'Extended' also i am able select the multiple rows but unable to catch the selected indexes or selected rows:( – nallskarthi Apr 26 '11 at 11:26
  • Well, yes, the binding of SelectedItems to the view model is a bit tricky for the simple reason that this property has no setter so that you can't bind from ViewModel to XAML... Try to check this link to see if you can find some hints about how to acheive this [link]http://stackoverflow.com/questions/3566658/multibinding-multiselection-listview/5620723#5620723 – Bruno Apr 26 '11 at 12:08
  • Thanks this is the only way i think. creating a new dependency property and then follow the same link which you mentioned above. – nallskarthi Apr 27 '11 at 03:48