C# DataGridViewComboBoxColumn binding problem

后端 未结 2 525
梦如初夏
梦如初夏 2021-02-10 09:25

Hey everyone! I suppose this is my first post on StackOverFlow.com :-)

I\'ve been having this problem for a while. To make it all simple, suppose we have 2 database tabl

2条回答
  •  [愿得一人]
    2021-02-10 10:04

    This should work:

    // create the column (probably better done by the designer)
    DataGridViewComboBoxColumn categoryColumn = ...
    
    
    // bind it
    categoryColumn.DataSource = db.Categories.ToList();
    categoryColumn.DisplayMember = "catName";  // display category.catName
    categoryColumn.ValueMember = "id";         // use category.id as the identifier
    categoryColumn.DataPropertyName = "catId"; // bind the column to book.catId
    

提交回复
热议问题