We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

SfDataGrid ComboBox Queries for nested and separate grids

Thread ID:

Created:

Updated:

Platform:

Replies:

124616 Jun 17,2016 08:56 AM Jun 24,2016 05:38 AM WPF 7
loading
Tags: SfDataGrid
Stoic Student
Asked On June 17, 2016 08:56 AM

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 and again that worked as expected

  1. However, when I tried to create a ComboBox in GroupsGrid using the above approach that didn't work presumably because the Binding to AreasCollection failed but I don't see a way in which I can refine the Binding.
  2. I then tried to create a ComboBox in the nested scenario using exactly the same statement that worked in step 4 but that produced nothing.

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,


Jai Ganesh S [Syncfusion]
Replied On June 20, 2016 10:24 AM

Hi Stoic, 
 
We have analyzed your query. In that you have bound the Bands and Groups Grid’s ItemsSource based on the SelectedItem of AreasGrid and BandsGrid respectively. Initially the SelectedItem is not set until we select the record. Hence the ItemsSource is not set while grid loaded and it will set when you click the cell.  
 
You can set the SelectedIem manually in Loaded event like below, 
 
void SfdataGrid_Loaded(object sender, RoutedEventArgs e) 
  { 
       var data=this.SfdataGrid.View.Records[3].Data; 
       this.SfdataGrid.SelectedItem = data; 
  } 
 
 
Could you please set the SelectedItem manually as we suggested above and it will fix your reported issues? Otherwise if you still facing the issue, please create the simple sample to state the issues? This would be more helpful for us to analyze further. 
 
Regards, 
Jai Ganesh S 


Stoic Student
Replied On June 20, 2016 12:38 PM

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


Jai Ganesh S [Syncfusion]
Replied On June 21, 2016 10:23 AM

Hi Stoic, 
 
For the ComboBox issues, we have prepared the sample for 3 nested levels of grid and define the ComboBox in the last level. Could you please define the combobox based on the below sample in your application? 
 
 
Screen shot: 
 
Still if you face the problem, then please modify the sample to replicate the issue. This would be more helpful for us to analyze further. 
 
Regards, 
Jai Ganesh S 


Jim
Replied On June 22, 2016 08:51 AM

 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


Jai Ganesh S [Syncfusion]
Replied On June 23, 2016 04:46 AM

Hi Stoic, 
 
We have modified our sample to bind the ComboBox column ItemsSource as a collection of object and showing the ComboBox column value based on the DisplayMemberPath. 
 
   
<syncfusion:GridComboBoxColumn MappingName="SupplierID" SelectedValuePath="SupplierID" 
 DisplayMemberPath="SupplierName" ItemsSource="{Binding  
Path=ComboBoxItemsSource,Source={StaticResource viewmodel}}"/> 
 
 
 
In the above sample, the ComboBox column value shows the SupplierName value. 
 
Regards, 
Jai Ganesh S 


Stoic Student
Replied On June 23, 2016 12:22 PM

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


Jai Ganesh S [Syncfusion]
Replied On June 24, 2016 05:38 AM

Hi Stoic, 
 
Thank you for the update. 
 
Please let us know if you need further assistance on this. 
 
Regards, 
Jai Ganesh S 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;