I have Master-Detail datagrid
in my application created using Linq to Entities
. I would like to display the selected row's deatils of the Master datagrid on the details datagrid.
what I have tried
private void Page_Loaded(object sender, RoutedEventArgs e)
{
this.db = new DB_ProdEntities();
var serverQuery = from a in this.hmdb.Servers
orderby a.ServerID
select a;
dgServer.ItemsSource = null;
dgServer.ItemsSource = serverQuery;
}
private void dgServer_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
string serverID = (dgServer.SelectedItem as Server).Name;
var componentQuery = from a in db.Components
where a.ServerID == serverID
orderby a.Name
select a;
dgComponent.ItemsSource = null;
dgComponent.ItemsSource = componentQuery;
}
OUTPUT:
when I select the first row everything is normal, but when I select the second row it displays the details along with the selection of the first row's details like this
Output 1
http://postimg.org/image/9x1f616n7/Output 2
http://s16.postimg.org/4nylei9ph/op2.png
how to overcome this problem?