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.
Syncfusion Feedback

Binding ItemsSource of GridComboBoxColumn

Thread ID:

Created:

Updated:

Platform:

Replies:

118162 Feb 6,2015 04:27 AM Feb 12,2015 07:26 AM WPF 4
loading
Tags: SfDataGrid
Emanuele Panzavolta
Asked On February 6, 2015 04:27 AM

Hi,

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

Saravanan M [Syncfusion]
Replied On February 9, 2015 11:21 PM


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



Saravanan M [Syncfusion]
Replied On February 11, 2015 12:43 AM


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



Emanuele Panzavolta
Replied On February 11, 2015 03:14 AM

Hi Saravanan, thanks for your last update. In fact this is what I meant, to set ItemsSource for each row, based on Gender. It's a pity that this is not possible directly in GridComboBox column, but the solution you suggest (to use GridTemplateColumn) allows to accomplish the goal; so thanks for that!

Many thanks,
Emanuele

Saravanan M [Syncfusion]
Replied On February 12, 2015 07:26 AM

Hi Emanuele

Thanks for your update. Please let us know if you need further assistance .

Regards,

Saravanan.M



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.

Warning Icon 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.Close Icon

;