Using version 28.2.7 of the WinForm Controls, I am unable to bind the value of the SfComboBox to the of value that is in another data source. I am attempting to follow the Data Binding section of the SfComboBox.
For example, the ComboBox is populated with static data from Table A. The data source of the main form is populated from the values in Table B.
The Display and Value Members of the ComboBox are set to the appropriate properties from Table A, and these values are displayed correctly when the data source of the ComboBox is populated directly from the results of the database query. However, I am unable to correctly bind the value of the data source of the main form so that the selected Item in the ComboBox is the value of the data source of Table B.
When using the built-in ComboBox from Microsoft, once the data source of the ComboBox is set, you use the DataBindings of the ComboBox to bind the value of Table B to the SelectedValue of the ComboBox. I have tried binding the value of Table B to the SfComboBox.ValueMember, but that does work correctly.
When I populate the BindingSource of the ComboBox, no values are displayed. It seems that I have to populate the DataSource of the ComboBox directly, for any values to be displayed.
Designer:
private Syncfusion.WinForms.ListView.SfComboBox CmbStatus;
CmbStatus = new Syncfusion.WinForms.ListView.SfComboBox();
//
// CmbStatus
//
CmbStatus.DataBindings.Add(new Binding("ValueMember", ParcelInformationResponseBindingSource, "PropertyTypeId", true, DataSourceUpdateMode.OnPropertyChanged));
//CmbStatus.DataSource = PropertyTypeResponseBindingSource;
//CmbStatus.DisplayMember = "TypeName";
CmbStatus.DropDownPosition = Syncfusion.WinForms.Core.Enums.PopupRelativeAlignment.Center;
CmbStatus.DropDownStyle = Syncfusion.WinForms.ListView.Enums.DropDownStyle.DropDownList;
CmbStatus.Location = new Point(244, 37);
CmbStatus.Name = "CmbStatus";
CmbStatus.Size = new Size(142, 26);
CmbStatus.Style.TokenStyle.CloseButtonBackColor = Color.FromArgb(255, 255, 255);
CmbStatus.TabIndex = 5;
//CmbStatus.ValueMember = "Id";
//
// PropertyTypeResponseBindingSource
//
PropertyTypeResponseBindingSource.DataSource = typeof(PropertyTypeResponse);
Data:
private async Task GetPropertyTypeAsync()
{
//BindingList < PropertyTypeResponse > dataSource = [];
IEnumerable<PropertyTypeResponse> propertyTypes = await _mediator.Send(new PropertyTypeGetAllQuery(m_CorrelationId));
//foreach (PropertyTypeResponse propertyType in propertyTypes)
//{
// dataSource.Add(propertyType);
//}
// Populating the BindingSource does not display any values when the form is opened
//PropertyTypeResponseBindingSource.DataSource = propertyTypes;
// Populating the Data Source of the ComboBox at least displays values,
// but the selected Item is not that of ParcelInformationResponseBindingSource.PropertyTypeId
CmbStatus.DataSource = propertyTypes.ToList();
CmbStatus.DisplayMember = nameof(PropertyTypeResponse.TypeName);
CmbStatus.ValueMember = nameof(PropertyTypeResponse.Id);
}
private async Task GetRealEstateDataAsync()
{
IEnumerable<ParcelInformationResponse> parcelInformation = await _mediator.Send(new ParcelInformationGetByTaxYearQuery(2025, m_CorrelationId));
ParcelInformationResponseBindingSource.DataSource = parcelInformation;
}
Data Records:
public selead record PropertyTypeResponse(int Id, string TypeCode, string TypeName, string TypeDescription,
decimal SortOrder, bool IsCustom, bool IsInactive, string? CategoryCode, string? CustomCode)
: BaseDto();
public sealed record ParcelInformationResponse(int Id, int PropertyTypeId, string Description1, string? Description2,
int OriginalLand, int OriginalBuilding, int OriginalTotal, string Location1, string? Location2,
ParcelResponse Parcel, TaxYearResponse TaxYear, ParcelSpecificResponse ParcelSpecific, MortgageLenderResponse MortgageLender,
ContactInformationResponse ContactInformation, AddressInformationResponse AddressInformation)
: BaseDto();
public abstract record BaseDto();
I forgot to mention that when I edit the Designer and change the DataBindings from this:
CmbStatus.DataBindings.Add(new Binding("ValueMember", ParcelInformationResponseBindingSource, "PropertyTypeId", true, DataSourceUpdateMode.OnPropertyChanged));
To this:
CmbStatus.DataBindings.Add(new Binding("SelectedValue", ParcelInformationResponseBindingSource, "PropertyTypeId", true, DataSourceUpdateMode.OnPropertyChanged));
The ComboBox displays the correct information. If this is the ultimate solution, I would expect the "SelectedValue" item to be displayed in the list of Properties in the Advanced DataBindngs Editor.
Hi Greg,
We have validated your query regarding the data binding behavior and found that ValueMember only defines the property that represents the value, but it does not handle selection synchronization with the bound data source.SelectedValue is responsible for selecting the item in the ComboBox that matches the bound value .Thus, binding to SelectedValue instead of ValueMember ensures that the correct value is displayed in the ComboBox.
Additionally, regarding the inclusion of SelectedValue in the Advanced DataBinding Editor,we have analyzed your requirement for “Inclusion of SelectedValue in Advanced DataBinding Editor”. We have logged a feature request for the same. We will implement this feature in any of our upcoming releases.
At the planning stage for every release cycle, we review all open features and identify features for implementation based on specific parameters including product vision, technological feasibility, and customer interest. We will let you know when this feature is implemented. We appreciate your patience until then.
Thank you for requesting this feature and helping us define it. We are always trying to make our products better and feature requests like yours are a key part of our product growth efforts.
Feedback link: https://www.syncfusion.com/feedback/65913/inclusion-of-selectedvalue-in-advanced-databinding-editor
If you have any more specifications/suggestions for the feature request, you can add them as a comment in the portal and cast your vote to make it count.
Regards,
Nithi Sneha S