1つの解決策は、選択から一部の項目を無効にすることです。
はこれを試してみてください:
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.DrawMode = DrawMode.OwnerDrawFixed;
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string itemText = comboBox1.GetItemText(comboBox1.SelectedItem);
if ((itemText == "Admins") || (itemText == "Users"))
comboBox1.SelectedIndex = -1;
}
private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
{
string itemText = comboBox1.GetItemText(comboBox1.Items[e.Index]);
if ((itemText == "Admins") || (itemText == "Users"))
{
using (var f = new Font("Microsoft Sans Serif", 8, FontStyle.Bold))
e.Graphics.DrawString(itemText, f, Brushes.Black, e.Bounds);
}
else
{
e.DrawBackground();
using (var f = new Font("Microsoft Sans Serif", 8, FontStyle.Regular))
e.Graphics.DrawString(itemText, f, Brushes.Black, e.Bounds);
e.DrawFocusRectangle();
}
}
それはあなたが望むものではありませんが、それは次善の策です。
あなたはどのUIフレームワークを使用していますか? WinFormsまたはWPF? –
私はWinFormsを使用しています –
追加情報で質問を更新するだけで、コメントに追加しないでください – MikeT