C# Set combo item with selectedValue

前端 未结 6 704
生来不讨喜
生来不讨喜 2020-12-11 03:55

I am dynamically creating a combobox like this:

public Control GenerateList(Question question)
{
    // Get a list with answer possibilities
    List

        
6条回答
  •  佛祖请我去吃肉
    2020-12-11 04:19

    Are you looking at the same property?

     cmb.ValueMember = "Id"; 
     ..
     cmb.SelectedValue = givenAnswers[0].AnswerId; 
    

    You're refering to another ValueMember then the Id you're posting into the SelectedValue. Besides that you might want to try to set your Display- and Value-member before databinding. It's faster.

提交回复
热议问题