Programmatically adding GridComboBoxColumn to the grid
|
<Syncfusion:SfDataGrid x:Name="sfDataGrid2"
HorizontalAlignment="Left"
Height="159"
VerticalAlignment="Top"
Width="922"
AllowFiltering="True"
RowHeaderWidth="15"
AllowEditing="True"
FooterRowsCount="1"
RowHeight="18"
AutoGenerateColumns="False"
AutoGenerateColumnsMode="ResetAll">
</Syncfusion:SfDataGrid>
//Column definition
sfDataGrid2.Columns.Add(new GridNumericColumn()
{
HeaderText = "Article ID",
MappingName = "id",
NumberDecimalDigits = 0,
ColumnSizer = GridLengthUnitType.SizeToHeader
});
sfDataGrid2.Columns.Add(new GridTextColumn() { HeaderText = "Name", MappingName = "name" });
//This column is only to show that data exists in this column
sfDataGrid2.Columns.Add(new GridNumericColumn() { HeaderText = "Group ID", MappingName = "idgroup", NumberDecimalDigits = 0, ColumnSizer = GridLengthUnitType.SizeToHeader });
sfDataGrid2.Columns.Add(new GridComboBoxColumn()
{
MappingName = "idgroup",
ItemsSource = view.ComboBoxDetails.DefaultView,
HeaderText = "Group",
DisplayMemberPath = "groupname",
SelectedValuePath = "idgroup"
});
sfDataGrid2.ItemsSource = view.Details.DefaultView; |
Thank you for the reply. I still have the same problem.
When I run your project I get this
When I click on the Group field I can see Drink and Food in Combobox
but after selection, nothing is displayed in previous field
This is the same problem I had before. Could you please advise how to proceed.
Best regards,
Hi,
my bad. I still have 14.2460.0.26 version installed. I installed 15.0.2.40 right away to check it. The newest version I installed on my laptop but I didn't tried there.
I will try and get back to you.
Thanks for your effort and time.
Hi,
my bad. I still have 14.2460.0.26 version installed. I installed 15.0.2.40 right away to check it. The newest version I installed on my laptop but I didn't tried there.
I will try and get back to you.
Thanks for your effort and time.
Hi
just to confirm it works with new version.
Thank you again.
When customizing your grid by programmatically adding a GridComboBoxColumn, it’s helpful to consider how users interact with individual selections or items. Similarly, Wendy's Menu Price provides updated details for each menu item, giving a clear snapshot for easy selection. Just like in grids, having precise item information makes decision-making smoother and more efficient.
You’re very close — the issue is mainly about binding the ComboBox value correctly.
GridComboBoxColumn needs both a display field and a value field so it knows how to map the selected item back to the underlying idgroup in your Articles table.
Right now, you’ve set DisplayMemberPath, but you’re missing SelectedValuePath.
What to fix
Add SelectedValuePath = "idgroup" to the GridComboBoxColumn.
Corrected column code
sfDataGrid2.Columns.Add(new GridComboBoxColumn()
{
HeaderText = "Group",
MappingName = "idgroup", // Binds to Articles.idgroup
ItemsSource = ds.Tables["Groups"].DefaultView,
DisplayMemberPath = "groupname", // What user sees
SelectedValuePath = "idgroup" // What gets stored
});
Why this works
MappingName→ value in Articles (idgroup)ItemsSource→ lookup table (Groups)DisplayMemberPath→ shown text (groupname)SelectedValuePath→ actual value written back (idgroup)
Without SelectedValuePath, the grid doesn’t know how to match idgroup to an item in the combo box, so it renders empty.
After this change, the column should correctly show Drink / and update idgroup as expected.
You’re missing SelectedValuePath. The combo box can’t match idgroup to the lookup table without it.
Add this:
SelectedValuePath = "idgroup"
That will correctly display Food/Drink while binding to idgroup.
- 10 Replies
- 6 Participants
-
DF df
- Jul 15, 2017 08:41 AM UTC
- Jan 22, 2026 03:31 AM UTC