如何动态添加组合框项目?
我有一个组合框,我将在OnChange Call Back事件期间调用API。将项目加载到组合框时遇到问题
public void OnChange(Office.IRibbonControl control, string text)
{
var result = GETMembersList("https://restcountries.eu/rest/v1/all");
var members = from member in result
select member;
foreach (var member in members)
{
dsMember mem = new dsMember();
mem.Id = member["numericCode"].ToString();
mem.Name = member["name"].ToString();
RibbonDropDownItem item = Globals.Factory.GetRibbonFactory().CreateRibbonDropDownItem();
item.Label = mem.Name;
**cmbMembers.Items.Add(item);** ?? //problem here, cant access the combo box
}
Ribbon.xml
<?xml version="1.0" encoding="UTF-8"?>
<customUI onLoad="Ribbon_Load" xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon>
<tabs>
<tab id="tabTest" label="TEST">
<group id="grpTest">
<comboBox id="cmbMembers" label="Users" showImage="false"
onChange="OnChange"/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
答案 0 :(得分:0)
VISTO有一个问题,我也试过从代码中添加多个项目,但出了点问题。 但是,可以动态修改现有项目。 尝试在Ribbon1_Load事件中进行编辑。
public partial class Ribbon1
{
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
this.comboBox1.Items[0].Label = "new Lable";
}
}
答案 1 :(得分:0)
尝试一下:
RibbonDropDownItem item = Factory.CreateRibbonDropDownItem();