Click here to Skip to main content
15,903,856 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hiiiii
how can i hide some values on combobox and after some changes, return and come back to normal values of this combobox?
help me please. i have a serious problem
Posted
Comments
CodeBlack 11-Nov-13 5:23am    
can you please make your question more clear with code you have tried ?
mohsenvasefi 11-Nov-13 6:40am    
if (comboBox44.SelectedIndex == 0)
{
S_DRV_Byte26 = (byte)(S_DRV_Byte26 | 0x00);
(i need to hide some value of combobox43 here and in next selection of combobox, initialize again)
}
else
{
S_DRV_Byte26 = (byte)(S_DRV_Byte26 & 0xff);
}
Richard MacCutchan 11-Nov-13 5:43am    
Just rtemove the values you do not want to be shown, and then restore them when required.
mohsenvasefi 11-Nov-13 6:32am    
what can i restore them? i think if i can hide them, it can help me more!

1 solution

This code demonstrates adding, and restoring, the seventh Item in a WinForms ComboBox:
C#
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    if (comboBox1.Items.Contains("Item 7"))
    {
        comboBox1.Items.RemoveAt(6);
        // or use Remove("Item 7");
    }
    else
    {
        comboBox1.Items.Insert(6, "Item7");
    }
}
You'll have to store and keep track of which items you remove, and where they should be inserted when you need to restore them.

You should read the documentation on the ComboBox.ObjectCollection Class' 'Contains, 'RemoveAt, and 'Insert methods.
 
Share this answer
 
Comments
mohsenvasefi 11-Nov-13 6:44am    
thank you, but my problem is about two comboboxes that one of them controlled another, not itself! like below code:
if (comboBox44.SelectedIndex == 0)
{
S_DRV_Byte26 = (byte)(S_DRV_Byte26 | 0x00);
(hide some value of combobox43 here and in next selection of combobox, initialize again)
}
else
{
S_DRV_Byte26 = (byte)(S_DRV_Byte26 & 0xff);
}
BillWoodruff 11-Nov-13 6:50am    
You can easily use the code shown here: just remove the Items from ComboBox43 when the user selects Item 0 in ComboBox44, and restore them when they select Item 1.
mohsenvasefi 11-Nov-13 8:39am    
why my code has wrong result?

if (comboBox44.SelectedIndex == 0)
{
S_DRV_Byte26 = (byte)(S_DRV_Byte26 | 0x00);
comboBox43.Items.RemoveAt(2); comboBox43.Items.RemoveAt(2);
}
else
{
S_DRV_Byte26 = (byte)(S_DRV_Byte26 | 0x01);
S_DRV_Byte26 = (byte)(S_DRV_Byte26 & 0xff);
comboBox43.Items.RemoveAt(0); comboBox43.Items.RemoveAt(0);
comboBox43.Items.Insert(2, "AGFS");
comboBox43.Items.Insert(3, "MGFS");
}
comboBox43.Items.Insert(0, "APS");
comboBox43.Items.Insert(1, "MPS");
BillWoodruff 11-Nov-13 9:24am    
Try to give as complete information as possible in your original question; without knowing what's in each of the two ComboBoxes to begin with, I'm not going to turn my head inside-out trying to imagine what's going on.

One idea: bypass this whole problem by creating two ComboBoxes of the same size, positioned at the same location, and depending on what the user selects in the first ComboBox, use 'BringToFront() to move the correct one in front of the other ... or use Hide/Show.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900