Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have the following very simple model:
C#
public class Product
 {
     [Key]
     public int ProductId { get; set; }
     public string Descripcion { get; set; }
     public virtual Color Color { get; set; }
 }

 public class Color
 {
     [Key]
     public int Color_Id { get; set; }
     public string Name { get; set; }
 }

I add a Datagrid Control by dragging the "Product" from my Data Sources into my Form. Then change the column for Product to DataGridViewComboBox and perform the following initialization
C#
db.Products.Load();
this.productBindingSource.DataSource = db.Products.Local.ToBindingList();
ColorCol.DataSource = db.Colors.ToList();
ColorCol.DisplayMember = "Name";
ColorCol.ValueMember = "Color_Id";
ColorCol.DataPropertyName = "Color_Color_Id";


"Color_Color_Id" is the name of the database FK field in the products table. I have also tried with "Color.Color_Id" and "Color"
When I execute the program, it correctly displays the ProductId and Description fields.
It also displays the comboBox which correctly displays the different color option when clicked.

The problem is the combobox is not displaying the the color of the product being displayed in the row, neither the Product.Color is updated when I select a different color in the ComboBox.
So I'm missing the connection between my combobox and my products

What I'm expecting is that the DatagridView controls displays the products in rows and that I'm able to change a product's color by selecting a diferent color in the combobox

So far I have been unable to find a proper answer. help is very much appreciated
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900