How to disable items in a Visual FoxPro ComboBox or ListBox control (133743)



The information in this article applies to:

  • Microsoft Visual FoxPro 9.0 Professional Edition
  • Microsoft Visual FoxPro 8.0
  • Microsoft Visual FoxPro for Windows 7.0
  • Microsoft Visual FoxPro for Windows 6.0

This article was previously published under Q133743

SUMMARY

This article describes how to disable items in Visual FoxPro (VFP) ComboBox and ListBox controls.

MORE INFORMATION

To disable items in a VFP ComboBox or ListBox control, precede the items with a backslash (\) character. Items in a VFP ComboBox or ListBox control can only be disabled when the RowSourceType property of the ComboBox or ListBox control is set to one of the following values:
  • 0-None
  • 1-Value
  • 5-Array

For example, you may try to disable items in a ComboBox or ListBox control with a RowSourceType property value of "6-Fields" by preceding the item with a backslash to the data in the cursor that is used to fill the control. However, this will not work, and the result is that the backslash and the data will appear in the control and the item will not be disabled.

The following sample code creates a VFP form with two controls: a ComboBox and a Listbox. Code in the INIT() event of the form adds thirty (30) items to each control through the AddItem() method. As the items are added, every second item is disabled by preceding the item with a backslash (\) and closing bracket (]). As mentioned earlier, only the backslash is necessary to disable the item, but the bracket is added to work around a second issue specific to the Listbox control (see to the "References" section later in this article for more information about that issue).

To use this sample, copy and paste the code into a new program in Visual FoxPro and then save and run the code. Notice the disabled items in both the ComboBox and ListBox controls, and notice also that these disabled items are inaccessible using either the keyboard or mouse.
PUBLIC oform1
oform1=NEWOBJECT("form1")
oform1.SHOW()
RETURN


*----------------
DEFINE CLASS form1 AS FORM
	HEIGHT = 252
	WIDTH = 319
	AUTOCENTER = .T.

	ADD OBJECT combo1 AS COMBOBOX WITH ;
		HEIGHT = 24, ;
		LEFT = 38, ;
		TOP = 41, ;
		WIDTH = 114, ;
		NAME = "Combo1"

	ADD OBJECT list1 AS LISTBOX WITH ;
		HEIGHT = 170, ;
		LEFT = 166, ;
		TOP = 41, ;
		WIDTH = 114, ;
		NAME = "List1"

	PROCEDURE INIT
		LOCAL i, lcValue
		FOR i = 1 TO 30
			lcValue = ;
				IIF( MOD( i, 2 ) == 0, '\]', '') + SYS(2015)
			THIS.list1.ADDITEM( lcValue )
			THIS.combo1.ADDITEM( lcValue )
		ENDFOR
	ENDPROC
ENDDEFINE

REFERENCES

For more information about disabling ListBox and ComboBox items in Microsoft Visual FoxPro, click the following article number to view the article in the Microsoft Knowledge Base:

156737 BUG: Disabled ListBox items can be accessed by using the keyboard in Visual FoxPro for Windows


Modification Type:MajorLast Reviewed:8/4/2005
Keywords:kbcode KB133743 kbAudDeveloper