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. Image for the cookie policy date

Creating Lookup field with SfDataGrid Combobox

Hello,

I have a project that display tabular data with SfDataGrid and have include a Combobox column which allows user to select from a predefined list. The Combobox has different datasource.

The problem I have is that when Combobox ValueMember is set different field other the DisplayMember it does not work, e.g

loc.ValueMember = "LocId";

loc.DisplayMember = "LocationName";

The above code block works but the one below does not work

loc.ValueMember = " LocationName ";

loc.DisplayMember = "LocationName";

But my requirement is that I want LocId(ValueMember) to be set by customer selecting LocationName(DisplayMember) from the Combobox .

Please find below relevant sections of the code

GridComboBoxColumn declaration:

GridComboBoxColumn loc = (GridComboBoxColumn)sfDespatch.Columns["StockLocation"];

loc.DataSource = StockLocationLookups;

loc.ValueMember = "LocId";

loc.DisplayMember = "LocationName";


DataSource:

public List StockLocationLookups => _unitOfWork.StockLocations.GetStockLocationLookups().ToList();


StockLocationLookup class:

public class StockLocationLookup

{

[Display(Name = "No")]

public int LocId { get; set; }

[Display(Name = "Location Name")]

public string LocationName { get; set; }

}


Thanks in advance for your usual assistance.


2 Replies 1 reply marked as answer

DM Dhanasekar Mohanraj Syncfusion Team April 6, 2023 12:24 PM UTC

Hi Paul,

We have checked the reported scenario with the provided details. We suspect that the reported issue occurs because of the type mismatch. By default, the ValueMember should be the same type as the Mapping name. When the type gets mismatched this kind of problem occurs. Here, we have attached a sample like your scenario, please have a look at this. If you still facing the reported issue, please modify the attached sample based on your scenario. It will be helpful for us to check on it and provide you with a solution at the earliest.

Regards,

Dhanasekar M.

If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Attachment: SfDataGridDemo_5871c273.zip

Marked as answer

PA Paul April 7, 2023 06:07 PM UTC

Hello Dhanasekar,


Thanks for the prompt response. I will implement your suggestion and revert to you with feedback


Best regards,


Paul Aziz


Loader.
Live Chat Icon For mobile
Up arrow icon