Colouring Combo Box Items

Set the ComboBox 'Draw Mode' to OwnerDrawFixed and then add this DrawItem event Colouring Text private: System::Void cmbMyComboBox_DrawItem(System::Object^ sender, System::Windows::Forms::DrawItemEventArgs^ e) { e->DrawBackground(); if (e->Index >= 0) { ComboBox ^ClickedComboBox = dynamic_cast<ComboBox^>(sender); String ^text = Convert::ToString(ClickedComboBox->Items[e->Index]); System::Drawing::Font ^Font1 = ClickedComboBox->Font; System::Drawing::Brush ^Brush1; if (e->Index == 0) Brush1 = Brushes::Red; else Brush1 = Brushes::Green; e->Graphics->DrawString(text, Font1, Brush1, […]

Read More

Useful function to setup combo boxes

The Function //************************************* //************************************* //********** SETUP COMBO BOX ********** //************************************* //************************************* private: void SetupComboBox (System::Windows::Forms::ComboBox ^TargetComboBox, int DefaultItem, array ^Items) { try { TargetComboBox->BeginUpdate(); TargetComboBox->SelectedIndex = -1; TargetComboBox->Items->Clear(); //Remove any existing items for each (String ^ItemString in Items) TargetComboBox->Items->Add(ItemString); TargetComboBox->SelectedIndex = DefaultItem; //Select default item } catch (Exception ^) { } finally { TargetComboBox->EndUpdate(); } […]

Read More

.Using Combo Boxes

Only permitting items in the list (YOU HAVE TO REMEMBER TO DO THIS TO BLOCK USER ENTERING THEIR OWN VALUES) DropDownStyle = DropDownList (Only accepts strings that are part of the selection list) Loading the contents of a comboBox at application startup cmbMyComboBox->BeginUpdate(); cmbMyComboBox->SelectedIndex = -1; cmbMyComboBox->Items->Clear(); //Remove Existing Items If Necessary for (Count = […]

Read More