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
close icon

Two GridComboBoxColumn with different display member

I have sfDataGrid bounded with a model and i have two GridComboBoxColumn with the same value member and different display member and when i add a new record it show the same value! how can i show the according display member for the second gridcomboboxcolumn?

//GridComboBoxColumn populating code
List<ProductModel> model = GlobalConfig.Connection.GetAllProducts(string.Empty, 0, 0);

//Product code
(this.gridViewPurchaseOrderDetail.Columns[3] as GridComboBoxColumn).DataSource = model;
(this.gridViewPurchaseOrderDetail.Columns[3] as GridComboBoxColumn).DisplayMember = "ProductCode";
(this.gridViewPurchaseOrderDetail.Columns[3] as GridComboBoxColumn).ValueMember = "ProductId";
//Description
(this.gridViewPurchaseOrderDetail.Columns[4] as GridComboBoxColumn).DataSource = model;
(this.gridViewPurchaseOrderDetail.Columns[4] as GridComboBoxColumn).DisplayMember = "Description";
(this.gridViewPurchaseOrderDetail.Columns[4] as GridComboBoxColumn).ValueMember = "ProductId";               

//Add a new record to the grid
var orderDetailModel = new OrderDetailModel
{
                OrderDetailId = 0,
                OrderId = _orderId,
                Quantity = 1,
                ProductId = selectedProduct.ProductId,
                UnitCost = selectedProduct.UnitCost,
                Tax = selectedProduct.Tax,
                TaxRate = GetTaxRateByName(selectedProduct.Tax)
};

var record = this.gridViewPurchaseOrderDetail.View.CreateRecordEntry(orderDetailModel);
this.gridViewPurchaseOrderDetail.View.Records.Add(record);

Attachment: Screenshot_ec3cd71c.rar

3 Replies

GG Gowtham Gopalsamy Syncfusion Team October 14, 2019 12:27 PM UTC

Hi Riad   
    
Thank you for using Syncfusion controls.     
  
We have analyzed your query “To have two GridComboBoxColumn with the same value member and different display member and add the new value in the GridComboBoxColumn, the same value can be shown in both combobox column”. This is the behavior of the combobox column.   
  
Please let us know the reason why you are using same value member for the both GridComboBoxColumn? You can use the different datasource collection for GridComboBoxColumn.   
  
Please let us know, if you require further assistance on this.   
   
Regards,       
Gowtham     



RI Riad October 14, 2019 11:12 PM UTC

Because i want to display the product code and description product on purchase order detail but i have just productId in order detail as foreign key of product table i tried that with devexpress component and it worked fine, is there a solution for that without adding a field to order detail table 


GG Gowtham Gopalsamy Syncfusion Team October 15, 2019 12:58 PM UTC

Hi Riad,    
                                                                                                                           
Thanks for using Syncfusion controls.    
    
You can achieve your requirement to have two GridComboBoxColumn with the same value member and different display member and add the new value in the GridComboBoxColumn and you can set the different MappingName for GridComboBoxColumn.  
 
Please refer the below code snippet, 
 
 
this.sfDataGrid1.Columns.Add(new GridComboBoxColumn() { MappingName = "ShipCity", HeaderText = "Ship City", DisplayMember = "ShipCityName", ValueMember = "ShipCityID", DropDownStyle = DropDownStyle.DropDownList, DataSource = orderInfo.ShipCityDetails }); 
 
this.sfDataGrid1.Columns.Add(new GridComboBoxColumn() { MappingName = "ShippedID", HeaderText = "Shipped ID", DisplayMember = "ShipID", ValueMember = "ShipCityID", DropDownStyle = DropDownStyle.DropDownList, DataSource = orderInfo.ShipCityDetails }); 
 
 
Please refer the below sample link, 
 
    
Please let us know if you require further other assistance from us.          
    
Regards,    
Gowtham    
 


Loader.
Live Chat Icon For mobile
Up arrow icon