Set the selecteditem of a combobox based on key,value pair.

后端 未结 4 860
情深已故
情深已故 2021-01-27 17:32

I have a combobox that I populate like this:

this.reqTypeInput.Items.Add(new RequestType(\"Label 1\", \"Value1\"));
this.reqTypeInput.Items.Add(new RequestType(\         


        
4条回答
  •  攒了一身酷
    2021-01-27 18:05

    You can try this:

    RequestType type1 = New RequestType("Label 1", "Value 1");
    RequestType type2 = New RequestType("Label 2", "Value 2");
    
    reqTypeInput.Items.Add(type1);
    reqTypeInput.Items.Add(type2);
    
    this.reqTypeInput.SelectedIndex = this.reqTypeInput.Items.IndexOf(type1);
    

    HTH.

提交回复
热议问题