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

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
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

Lastnosti

ID članka: 133743 – Zadnji pregled: 20. jun. 2008 – Revizija: 1

Povratne informacije