first of all please do not confuse with my question title. It is a single seleteditem on Multiple datagrid ( not multipleselecteditems on a single datagrid).
I have multiple datagrids ( say three ), each datagrid from the lowest depends for its data from the selecteditem from the above datagrid. I have asked questions on selecteditem on datagrid by populating the data from a sqlserver few weeks ago, and i managed to solve this issue with some answers.
WPF SelectedItem binding between two datagrids[
^]
is it possible to use the same selecteditem of a datagrid on multiple datagrid's ? for example,in the previous problem it was only 1:1 datagrid, will it be possible to implement the same concept like there are three datagrids,
one - Person
two- PersonDetails
Three- PersonStatus
1. first the Person datagrid loads by default (from the database)
2. Persondetails table data is displayed when a selecteditem is clicked on the Person datagrid(achieved this already)
3. PersonStatus table data should be displayed when the selecteditem is clicked on Persondetails( is this possible, it is like a tree one after the other)
This is how it will look like, I have achieved the selecteditem between the first two datagrid's
http://postimage.org/image/4cpoi2e07/[
^]
My MainViewModel.cs
public MainViewModel()
{
this.Persons = Person.GetPersons();
}
private ObservableCollection<Person> personValues;
public ObservableCollection<Person> Persons
{
get { return personValues; }
set { this.SetProperty<ObservableCollection<Person>>(ref this.personValues, value); }
}
public ObservableCollection<PersonDetails> Details
{
get
{
if (this.Selectedperson == null)
{
return null;
}
return this.LoadDetails(this.Selectedperson.PersonID);
}
}
private ObservableCollection<PersonDetails> LoadDetails(int personID)
{
ObservableCollection<PersonDetails> details = new ObservableCollection<PersonDetails>();
foreach (PersonDetails detail in PersonDetails.GetDetails().Where(item => item.PersonID == personID))
{
details.Add(detail);
}
return details;
}
private Person selectedPersonValue;
public Person Selectedperson
{
get { return selectedPersonValue; }
set
{
this.SetProperty<Person>(ref this.selectedPersonValue, value);
this.RaiseNotification("Details");
}
}
public ObservableCollection<PersonStatus> Statuses
{
get
{
if (this.SelectedDetail == null)
{
return null;
}
return this.LoadStatus(this.SelectedDetail.DetailID);
}
}
private ObservableCollection<PersonStatus> LoadStatus(int detailID)
{
ObservableCollection<PersonStatus> statuss = new ObservableCollection<PersonStatus>();
foreach (PersonStatus status in PersonStatus.GetStatus().Where(item => item.DetailID == detailID))
{
statuss.Add(status);
}
return statuss;
}
private PersonStatus selectedDetail;
public PersonStatus SelectedDetail
{
get { return selectedDetail; }
set
{
this.SetProperty<PersonStatus>(ref this.selectedDetail, value);
this.RaiseNotification("Statuses");
}
}
XAML
<Grid>
<DataGrid Margin="100,12,116,219" ItemsSource="{Binding Persons}" SelectedItem="{Binding Selectedperson, Mode=TwoWay}" />
<DataGrid Margin="100,110,116,121" ItemsSource="{Binding Details}" SelectedItem="{Binding SelectedDetail,Mode=TwoWay}" />
<DataGrid ItemsSource="{Binding Statuses}" Margin="100,210,116,21" />
</Grid>
when I try this code i get this following error :
http://s10.postimage.org/bxk7etjjd/SOerror.png[
^]
kindly help to proceed further. Thanks