I have a database with 3 tables of related data (Areas, Bands and Groups) and used Entity Framework to create the model. In my ViewModel I defined an ObservableCollection (AreasCollection) which obtains a collection of all Areas, including their related Bands and Groups. In my View I set its Data Context to point to the ViewModel and I set the SfDataGrid ItemsSource to AreasCollection.
I created an SfDataGrid with its ItemsSource="{Binding AreaCollection}" and used the DetailsViewDefinitions feature to display nested grids for each of Bands and Groups and everything worked as expected.
I then set out to show the same information in 3 separate SfDataGrids (AreasGrid, BandsGrid and GroupsGrid) linking the related grids by using ItemsSource="{Binding ElementName=AreasGrid, Path=SelectedItem.Bands}" for BandsGrid and ItemsSource="{Binding ElementName=BandsGrid, Path=SelectedItem.Groups}" for GroupsGrid. Again, that worked although I didn't understand why the related grids did not display until I clicked on a row in the AreasGrid.
Since I wanted a
simple way to change the Area to which a Band was related I created a ComboBox
in the BandsGrid to show the AreaName rather than the AreaID
Could you either show me where I've gone wrong or point me at relevant documentation for the above points as well as the issue above where the related grids do not show until I click on a cell.
Thanks,
void SfdataGrid_Loaded(object sender, RoutedEventArgs e)
{
var data=this.SfdataGrid.View.Records[3].Data;
this.SfdataGrid.SelectedItem = data;
}
|
Hi Jai,
Thanks for your help - manually setting the SelectedItem as you suggested worked excellently.
Could you help on the 2 ComboBox issues?
Thanks,
Stoic
Hi Jai,
Thanks for this. Not really sure what's happening in the solution you provided but the CustomerCity ComboBox shows "Chennai" and when clicked shows "Newyark, Spain etc" which seem to be derived from "List" in your ViewModel rather than the expected Cities list of "Chennai, Mumbai, Delhi etc " detailed in the repository.
The City ComboBox in the solution simply shows a list of all possible cities whereas what I'm trying to do is to show the ComboBox with the related City selected/displayed and when one clicks then the full Cities list is displayed. As I explained that works fine in separate SfDataGrids for one level of nesting
In your solution at NestedDetailsViewGrid2 there is a column defined as <syncfusion:GridTextColumn MappingName="SupplierName"/> but it actually shows the SupplierID so if you could show how one can display the SupplierName rather than the ID that would be helpful. I tried <syncfusion:GridComboBoxColumn ItemsSource="{Binding Source}" MappingName="SupplierID" SelectedValuePath="SupplierID" DisplayMemberPath="SupplierName" /> but that didn't work.
Thanks,
Stoic
<syncfusion:GridComboBoxColumn MappingName="SupplierID" SelectedValuePath="SupplierID"
DisplayMemberPath="SupplierName" ItemsSource="{Binding
Path=ComboBoxItemsSource,Source={StaticResource viewmodel}}"/>
|
Hi Jai,
Thanks for this which helpfully shows how to display the related Supplier for a selected Order.
The solution uses a separate collection of Suppliers whereas what I'm looking to resolve is whether the related records already in "source" (and which have therefore already loaded Supplier data) can be accessed rather than having to perform a separate action to populate the ComboBox.
However, since my requirement can be simply satisfied using related rather than nested grids I'll not take up any more of your resources.
Many thanks for your help.
Stoic