How To Create Multicolored Items in a Combo Box (185090)



The information in this article applies to:

  • Microsoft Visual FoxPro for Windows 3.0
  • Microsoft Visual FoxPro for Windows 3.0b
  • Microsoft Visual FoxPro for Windows 5.0
  • Microsoft Visual FoxPro for Windows 5.0a

This article was previously published under Q185090

SUMMARY

This article illustrates how you can create multicolored items in a combo box using Visual FoxPro versions 3.x and 5.x.

MORE INFORMATION

To create multicolored items in a combo box, the setting of the combo box RowSourceType has to be 9-popup and the RowSource property has to be set to the name of the popup.

The following steps illustrate how to accomplish this:

  1. Create a form.
  2. Place in the following code in the INIT event of the form:
          #DEFINE RedBar ,RGB(150,0,0)
          #DEFINE GreenBar ,RGB(0,150,0)
          #DEFINE BlueBar ,RGB(0,0,255)
          #DEFINE YellowBar ,RGB(255,255,0)
    
          DEFINE POPUP MultiColor
    
          DEFINE BAR 1 of MultiColor ;
             Prompt "Red" COLOR RedBar
    
          DEFINE BAR 2 of MultiColor ;
             Prompt "Green" COLOR GreenBar
    
          DEFINE BAR 3 of MultiColor ;
             Prompt "Blue" COLOR BlueBar
    
          DEFINE BAR 4 of MultiColor ;
             Prompt "Yellow" COLOR YellowBar
    							
  3. Add a Combo box object to the form and set the following properties:
          RowSourceType = 9 - popup
          RowSource = "MultiColor" (without quote)
    							
  4. In the InteractiveChange event of the combo box, place the following code:
          DO CASE
             CASE This.Value = "Red"
                This.Forecolor = RGB(150,0,0)
             CASE This.Value = "Green"
                This.Forecolor = RGB(0,150,0)
             CASE This.Value = "Blue"
                This.Forecolor = RGB(0,0,255)
             CASE This.Value = "Yellow"
                This.Forecolor = RGB(255,255,0)
          ENDCASE
    							
  5. Save and run the form.
When the form is run, click the combo box drop-down list. The items in the drop-down list appear in their respective colors.

Modification Type:MinorLast Reviewed:7/1/2004
Keywords:kbhowto KB185090