syncfusion : GridComboBoxColumn is not displaying data.
Hello,
[New to sfDataGrid, so experimenting and learning ]
I have defined <syncfusion:GridComboBoxColumn> and i am trying to bring the list for GridCombobox at runtime after a button click event. but list is not being populated. i guess i am doing some silly mistake.
<syncfusion:SfDataGrid x:Name="grid7"
HorizontalAlignment="Left" Height="513" Margin="33,288,0,0" AllowResizingColumns="True"
AutoGenerateColumns="False" ColumnSizer="Auto" VerticalAlignment="Top" Width="1437">
<syncfusion:SfDataGrid.Columns>
<syncfusion:GridTextColumn MappingName="ID"/>
.... (other columns )
<syncfusion:GridTextColumn MappingName="ResField" AllowEditing="True"/>
<syncfusion:GridComboBoxColumn HeaderText="" AllowEditing="True"
ItemsSource="{x:Bind ResObservableCollection}" DisplayMemberPath="Key" SelectedValuePath="Value"
MappingName="ResField" />
Where ResObservableCollection is local public variable of type ObservableCollection<Res> and Class Res is as below
public class Res
{
public string Key { get; set; }
public string Value { get; set; }
}
On Page_Loaded the grid7 gets its items source grid7.ItemsSource = fl.items; here items do have few rows, but only ResField will be empty and the role of UI is to accept values for this column from user. The list of values for GridComboBoxColumn is unknown until user selects a file that has values.
The button_click event retrieves the values from file into ResObservableCollection
this.ResObservableCollection = await resFileReader.ParseAsync(userSelectedFile);
My expectations was that since source is ObservableCollection, The GridComboBoxColumn will see the change in underlying source and update the list at runtime automatically. but that is not happening..
Any guidance or alternative approach please.
Regards
SIGN IN To post a reply.
4 Replies
MK
Muthukumar Kalyanasundaram
Syncfusion Team
January 17, 2018 04:07 AM UTC
Hi Jiya,
Thank you for contacting Syncfusion support.
In SfDataGrid, the GridComboBoxColumn will load the collection when defining DataContext before loading the SfDataGrid. When we are defining the DataContext in Page.Loaded event, the binding will not update for GridComboBoxColumn which loads the empty collection. But you can achieve this by using a DependencyObject class like below code example.
Code Snippet: C#
|
public class BindingProxy : DependencyObject
{
public BindingProxy() { }
//Dependency property Data for holding ComboBox ItemsSource value.
public object Data
{
get { return (object)GetValue(DataProperty); }
set { SetValue(DataProperty, value); }
}
// Using a DependencyProperty as the backing store for Data. This enables animation, styling, binding, etc...
public static readonly DependencyProperty DataProperty =
DependencyProperty.Register("Data", typeof(object), typeof(BindingProxy), new PropertyMetadata(null));
} |
Code Snippet: XAML
|
<Page.Resources>
<local:BindingProxy x:Key="proxy" Data="{Binding}"/>
</Page.Resources>
<syncfusion:SfDataGrid.Columns>
<!--Binding Dependency object in GridComboBoxColumn-->
<syncfusion:GridComboBoxColumn HeaderText="City" ItemsSource="{Binding Data.ItemsCollection, Source={StaticResource proxy}}" AllowEditing="True"
DisplayMemberPath="Key" SelectedValuePath="Value"
MappingName="City" />
</syncfusion:SfDataGrid.Columns>
|
Regarding this, we already have a KB documentation. Could you please refer the below link,
Please let us know if you have any question.
Regards,
Muthukumar K
JI
Jiya
January 17, 2018 04:01 PM UTC
Thanks for reply. I will surely try this and get back.
It would be helpful if there is any way to dynamically assign itemsSource to GridComboBoxColumn at runtime.
Regards
JI
Jiya
January 18, 2018 02:38 PM UTC
Hi Muthukumar K ,
Attachment: GridComboBoxDemo1_20c9ce68.zip
I tried your suggestion, but i was not successful, might be because i am not using viewModel. I am attached my sample code in your sample project.
All code is there in MyExperiments.xaml.
On start of page, you have to select a resw file (already attached in the project folder) and then grid will show up.
Regards
Attachment: GridComboBoxDemo1_20c9ce68.zip
GT
Gnanasownthari Thirugnanam
Syncfusion Team
January 19, 2018 10:30 AM UTC
Hi Jiya,
Please find the response for your queries.
|
Query 1: dynamically assign ItemsSource to GridComboBoxColumn at runtime. |
You can assign the ItemsSource to GridComboBoxColumn at runtime like below code example.
We have prepared the sample based on your requirement, you can download it from below mentioned location.
Sample location: http://www.syncfusion.com/downloads/support/directtrac/general/ze/GridComboBoxDemo-338419722
| |
|
Query 2: Still GridComboBoxColumn as Empty |
We had noticed that in your given code, you had assign the ItemsSource to field instead of property at runtime. Now we have modified the given files in that sample, you can download it from below mentioned location.
Sample location: http://www.syncfusion.com/downloads/support/directtrac/general/ze/GridComboBoxDemo1-1347191728
|
Please let us know if you need further assistance on this.
Regards,
Gnanasownthari T.
SIGN IN To post a reply.
- 4 Replies
- 3 Participants
-
JI Jiya
- Jan 15, 2018 11:56 AM UTC
- Jan 19, 2018 10:30 AM UTC