开发者

Convert String to Variable Name

I need get combobox by string. Not worked.

 for (int i = 0; i < Slots.Count; 开发者_运维百科i++)
        {
            var field = (ComboBox)this.GetType().GetField("cbSlots" + i).GetValue(this);
            field.DataSource = Slots[i.ToString()];
        } 


If I understand the question, from your form, you could do

this.Controls.Find("name_of_your_combobox");


If you are trying to access a ComboBox using its name as string, so you need to look for that in this.Controls like so:

ComboBox myCombo = (ComboBox)this.Controls["cbSlots" + i.ToString()];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜