How to add the Combo Box items dynamically ?
I have a Combo Box, where i will call the API during the OnChange Call Back event. Have a problem in loading the items to combo box
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>
试试这个:
RibbonDropDownItem item = Factory.CreateRibbonDropDownItem();
VISTO has an issue, I too tried adding multiple items from code behind but something went wrong. But, existing items can be modified dynamically. Try editing in Ribbon1_Load event.
public partial class Ribbon1
{
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
this.comboBox1.Items[0].Label = "new Lable";
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.