Binding ItemsSource of GridComboBoxColumn
I'm using the SfDataGrid, and trying to use GridComboBoxColumn.
In the examples, I've seen that the ItemsSource has usually a binding to a StaticResource, therefore it is shared across all the rows of the datagrid.
Now, my requirement would be to have an ItemsSource variable row by row. Basically, the ViewModel that is bound to each row, would contain both the IEnumerable (to be bound to ItemsSource) and the property to be bound to the selected item, via SelectedValuePath.
Just as an example, this is the pseudo-code
<sync:GridComboBoxColumn HeaderText="Title"
MappingName="SelectedTitle"
ItemsSource="{Binding AvailableTitles}"
SelectedValuePath="SelectedTitle"
AllowEditing="True" />
Where AvailableTitles and SelectedTitle are both properties of the viemodel class for each row.
This doesn't seem to work.
I've attached a ZIP that contains a demo solution for this.
Could you please indicate how I can achieve my requirement?
Thanks,
Emanuele
Attachment: SfDataGrid_Combobox1_4021a3bf.zip
Hi Emanuele,
We have checked with your sample . You have set DataContext as MainViewModel for Window. But it does not have AvilableTitles property which is binded for ComboBox ItemsSource. So you need to define the property in MainViewModel .
We have modified the sample based on your requirement and you can download it from below location.
Sample Location: SfDataGrid_Combobox1.zip
Please refer the below code snippet.
Code snippet[XAML]:
| <sync:GridComboBoxColumn AllowEditing="True" HeaderText="Title" ItemsSource="{Binding Path=DataContext.AvailableTitles, ElementName=grid}" MappingName="SelectedTitle" /> |
Please let us know if you have any other queries,
Regards,
Saravanan.M
Hi Emanuele,
Please ignore our previous update,
You can set the ItemsSource for each row based on the Gender by using GridTemplateColumn, where we have loaded the TextBlock in CellTemplate and ComboBox in EditTemplate with ItemsSource binding as you requested. We have prepared a sample based on this and you can download it from below location
Sample Location: SfDataGrid_Combobox1.zip
Please refer the below code snippet
Code snippet[XAML]:
| <sync:GridTemplateColumn HeaderText="Title" MappingName="SelectedTitle"> <sync:GridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock Margin="2,0" Text="{Binding Path=SelectedTitle}" /> </DataTemplate> </sync:GridTemplateColumn.CellTemplate> <sync:GridTemplateColumn.EditTemplate> <DataTemplate> <ComboBox ItemsSource="{Binding AvailableTitles}" SelectedValue="{Binding Path=SelectedTitle}" /> </DataTemplate> </sync:GridTemplateColumn.EditTemplate> </sync:GridTemplateColumn> |
Regards,
Saravanan.M
Many thanks,
Emanuele
Hi Emanuele
Thanks for your update. Please let us know if you need further assistance .
Regards,
Saravanan.M
- 4 Replies
- 2 Participants
-
EP Emanuele Panzavolta
- Feb 6, 2015 09:27 AM UTC
- Feb 12, 2015 12:26 PM UTC