I'm loading Strings to a Combobox -
cboIndexLanguage.Items.Add("ThisLanguage")
i would like to make several of these items invisible.
I'm loading Strings to a Combobox -
cboIndexLanguage.Items.Add("ThisLanguage")
i would like to make several of these items invisible.
Try sending a CB_SETMINVISIBLE
message for each item.
OR
simply don't set the Text value!
Later edit:
int invItems = 5;
Message msg = new Message();
msg.Msg = CB_SETMINVISIBLE;
msg.LParam = 0;
msg.WParam = invItems;
msg.HWnd = combo.Handle;
MessageWindow.SendMessage(ref msg);
OR invoke this:
[DllImport("user32.dll")]
public static extern int SendMessage(int hWnd, uint Msg, long wParam, long lParam);
you can use an other list to keep strings and show wanted items to user by combo box.To do that you can define a Refresh_Combo_Method that clears combo box items and copies item from list of string to combo , then indexes was in main list.
List<string> colorList = new List<string>();
colorList.Add ("Red");
colorList.Add ("Green");
colorList.Add ("Yellow");
colorList.Add ("Purple");
colorList.Add ("Orange");
...
colorList.Remove("Red");
colorList.Insert(2, "White");
colorList[colorList.IndexOf("Yellow")] = "Black";
colorList.Clear();
...
combobox.Items.Clear();
In thread-safe way you can do it pretty simple (if you only want to play with colors):
private delegate void SetBackColorDelegate(int index, Color color);
private void SetBackColor(int index, Color color)
{
if (cboIndexLanguage.InvokeRequired)
{
cboIndexLanguage.Invoke(new SetBackColorDelegate(SetBackColor), new object[] { index, color });
}
else
{
cboIndexLanguage.Items[index].BackColor = color;
}
}
In other way, you can just remove items from combo box but save them in some data structure f.ex:
class ComboElement
{
public String ComboElementText { get; set; }
public int Index { get; set; }
public ComboElement(String elementText, int index)
{
ComboElementText = elementText;
Index = index;
}
}
//* List of hidden elements.
List<ComboElement> hiddenElements = new List<ComboElement>();
then you want to show it again, you can take it from here, and insert into the right place (you know index).
add these to your combobox
class MyCboItem
{
public bool Visible { get; set; }
public string Value { get; set; }
public override string ToString()
{
if (Visible) return Value;
return string.Empty;
}
}