I'm sorry for I'm not good at English. this is my code: Code winform
for (int i = 10; i < 70; i++)
{
RibbonButton rbtn = new RibbonButton();
rbtn.Text = i.ToString();
ribbonComboBox2.DropDownItems.Add(rbtn);
}
//ribbonComboBox2.SelectedItem = ribbonComboBox2.DropDownItems[0];
//-----------Tạo danh sách font chữ
System.Drawing.Text.InstalledFontCollection fonts = new System.Drawing.Text.InstalledFontCollection();
foreach (FontFamily family in fonts.Families)
{
RibbonButton rbtn = new RibbonButton();
rbtn.Text = family.Name.ToString();
ribbonComboBox1.DropDownItems.Add(rbtn);
}
I didn't see any items when clicking the RibbonCombobox. Thank you everyone!
I'm not sure what you are using for the Ribbon control since I don't think that is native to winforms, but my guess is that when you say "I didn't see any items when clicking the RibbonCombobox." you are seeing that the combobox has items but they are displayed as blanks. This is most likely caused from the combobox not having the DisplayMember
property set.
for (int i = 10; i < 70; i++)
{
Button rbtn = new Button();
rbtn.Text = i.ToString();
ribbonComboBox2.Items.Add(rbtn);
ribbonComboBox2.DisplayMember = "Text";
}
System.Drawing.Text.InstalledFontCollection fonts = new System.Drawing.Text.InstalledFontCollection();
foreach (FontFamily family in fonts.Families)
{
Button rbtn = new Button();
rbtn.Text = family.Name.ToString();
ribbonComboBox1.Items.Add(rbtn);
ribbonComboBox1.DisplayMember = "Text";
}
To use the DisplayMember
, you set it equal to the name of the property that you want shown in your combobox. The name of the property should come from the items in the combobox. I used Button
and ComboBox
since I didn't know what you were using but I'm willing to bet that it will work just fine for you. The DisplayMember
is set to "Text" because you want to display the Text
property of your button.