1414
FAQ [Controls]
On this page are placed the answers to questions which I cruelly (or easy) found, I do not think, that the answers are exhausting, and if you will find, that something not conform to your representations, let's discuss and we shall find the best decisions... Besides frequently answer can depend on the version as OS and Visual FoxPro, to check up all on all versions and platforms for me simply excessively. Initially this list was only for VFP 5.0, while now it only VFP 7.0/8.0, I could somewhere and miss a mention of the version, and if you will find discrepancies, inform me, please.

а

Q: How to return the value numerical code from ComboBox with two fields (symbolical name, numerical code) for record with numerical field in the table, i.e. when the given tables for ComboBox are subordinated of some parental table with a numerical code field?а

A: For version Visual FoxPro 3.0 the exhausting answer the registered users can find in Internet to the address:http://msdn.microsoft.com/library/ (eng). In section Preodicals/FoxTalks/Volume 8 1996: (http://www.pinpub.com/foxtalk/) clause Use a Combo Box to Select Foreign Keys http://msdn.microsoft.com/library/periodic/period96/D1/FT0896.htm (for brevity details I here do not discuss). In version Visual FoxPro 5.0a it is enough at ComboBox to establish property BoundTo value .T., [distinct from .F. (Default)], certainly by determining properties: BoundColumn, ControlSource, RowSource and RowSourceType in appropriate way.

Q: How I can display the subordinated set of records in Grid for some record in the parental table, if a source of the data for Grid is View?а

A: Essentially, there are two opportunities to make it: to use parametrical query as a source of the data to Grid or to establish for it the appropriate property Filter. Each of these cases can much differ by quantity of the sent information between server of the data and client, it is necessary also to note, that in the first case you will need obvious using function REQUERY() for a source of the data Grid after moving of the current record in the parental table repeatedly to execute query of the data according to changing conditions. See also
Q142974 Views.exe - One-To-Many Form Using a Parameterized View эр Microsoft.com
Q156169 HOWTO: Ignore Parameters in View or Query If Blank

Q: How to add CheckBox and ComboBox as displayed elements of columns in Grid?а

A: First of all, it is necessary to note, that for CheckBox the type of the data of the field, appropriate to it of a source of the data should be by type logic, while use ComboBox means, that you determine for it properties: RowSource, RowSourceType, Style (data displayed in ComboBox or a binding source of the data) and ControlSource, BoundColumn, BoundTo (returned value, i.e. the edited field of the table - source of the data Grid, for which ComboBox actually also displays the binding value).
For addition CheckBox it is easiest to use Builder for Grid (call BuilderЕby right click button of the mouse), where on a tab Layout follows set Control type in CheckBox for the appropriate column Grid. Check, that before a call Builder the used tables previously were open, as it can analyze the contents only if tables is opened, giving you the information for adjustment.
The elements CheckBox or ComboBox can be added and during editing Grid. For this purpose choose your column as active (Column[i] in a window Properties) and drag the element, necessary to you, (CheckBox or ComboBox) from Forms Controls Toolbar and drop it in the first line Grid for required column. If now you will open ComboBox of objects in a window Properties, will see, that the element, chosen by you, is added as an element of a column (at once after Text1), though it is not active now. At last, to make active the element, added by you, reset property CurrentControl for a column Column[i] on the element, necessary to you.

Q: I would like on click of the mouse on heading of a column Grid to change an active index at a source. To change the index is carried out, but I thus lose the current record. How I need to make, that the record the after changed of an index remained former?а

A: In VFP6.0 magic action in Grid.Header.Click() following:
LOCAL lnRecNo
lnRecNo = IIF(!EOF(), RECNO(), 0)
ThisForm.DataEnvironment.cursor1.Order = "Column_Order" 
*-- or SET ORDER TO TAG Column_Order
WITH This.Parent.Parent
    .ActivateCell(1, .ActiveColumn)
    IF lnRecNo # 0
        GO (lnRecNo)
    ELSE
        GO TOP 
    ENDIF
    .Refresh()
ENDWITH
See also "PRB: Incremental Search with Grid Causes Screen Flicker" in MSDN

Q: At me the record in Grid does not deleted, explain please, as I should make it correctly.а

A: If at you the blocking of records in mode buffering record and property DeleteMark of Grid is established to .F., you can be helped by the following code:
...
WITH ThisForm
    IF VARTYPE(.ActiveControl) = "O";
        AND .ActiveControl.BaseClass == "Grid";
        AND !INLIST(CURSORGETPROP("Buffering"), 4, 5);
        AND !.ActiveControl.DeleteMark 
        *-- Grid with DeleteMark = .F. and buffering record has a problem
        *-- at delete of record, it is necessary temporarily
        *-- to establish property DeleteMark = .T. 
        LOCAL loGrid
        loGrid = .ActiveControl
        loGrid.DeleteMark = .T.
    ENDIF
ENDWITH
lnRecNo = RECNO()
DELETE
llError = !TABLEUPDATE(.T.)
IF TYPE("loGrid") = "O"
    loGrid.DeleteMark = .F.
ENDIF
...
See also: http://support.microsoft.com/kb/q191641/

Q: How in object Grid to remove (to hide from the screen), and later to restore, on a former place, column (object Column)? Thus, it is necessary that at removal column was replaced with the right column.а

A: Try the following in a event Header1.Click():
WITH This.Parent
    IF .Visible 
        .Visible = .F.
        .Width = 0
    ELSE
        .Visible = .T.
        .Width = 75 && -- or former size
                    ** -- from the previously created array-property of your form  
    ENDIF
ENDWITH

you can establish Grid1.GridLineColor = RGB (128, 128, 128), that the latent column "did not rush in eyes"... As, I hope, most simple variant...

Q: I want to add the data in ComboBox, so to have two columns, I do not have joined(attached) source of the data, the data I would like to add from the program, but at me nothing it turns out. How it can be made?а

A: If I correctly have understood a problem, you need to use: for the first column: .AddItem (...) ...and for all others: .AddListItem(...)

Q: I place on the form ActiveX-components ImageList and add to it Images. I place on the same form of ActiveX-components Toolbar. I put in it the reference on ImageList and then I complete editing Toolbara. I open it again, but reference - none. What do with it?а

A: Made initialization of a property MyForm. MyToolbar1. Object. ImageList in runtime, similarly to the following:
#DEFINE tbrDefault	0
#DEFINE tbrCheck	1
#DEFINE tbrButtonGroup	2
#DEFINE tbrSeparator	3
#DEFINE tbrPlaceholder	4
#DEFINE tbrDropDown	5 

#DEFINE MAXBUTTONS	2 

LOCAL lcCurKey, loButton, lnCntImg, lnCntBtn
lnCntImg = 0
WITH ThisForm.MyToolbar1.Object
	.ImageList = ThisForm.MyImageList.Object
	WITH .Buttons
		FOR lnCntBtn = 1 TO MAXBUTTONS
			lnCntImg = lnCntImg+1
			lcCurKey = SYS(2015)
			.Add(,lcCurKey)
			loButton = .Item(.Count)
			WITH loButton
				.Image = lnCntImg 
				* ... etc
			ENDWITH
			loButton = NULL
		ENDFOR	
	ENDWITH
ENDWITH
Pay attention on two moments:
Using of the key word Object to be addressed not to VFP-cover of object, but immediately to it's property/method
To receive the reference on Button, I use Buttons.Item(Buttons.Count) instead of returned by a method Add()
I suspect, that for this trivial object, it is all is looked as "superfluous things", but only up to some of case..., and certainly, all depends on the version of objects...: -)
See also Q163803 in MSDN

Q: It's impossible at me call UDF in ControlSource of a column Grid in the form.а

A: Try to use the following expression: (UDF(Table.Field1[,...])[...]). Pay attention on "superfluous" external brackets and actual parameter in UDF: table-field.

Q: I want to show value of a memo-field of the table in a column Grid, however at me the word Memo is mapped only, and I need value. How it can be made?а

A: The most simple method to add "superfluous" external parentheseses similarly to ThisForm.MyGrid.ColumnX.ControlSource = "(MyTable.MyMemoField)", also is possible to insert Editbox and reset CurrentControl of a column into Edit1 to map value of a memo-field through it.

Q: I want a multiple-line headers of columns in Grid. What it is possible to make?а

A: See ID: Q133164 in MSDN or on http://www.microsoft.ru/catalog/article.asp?article_id={4CA8A85C-B996-11D4-9DAA-00508B8B6DC3} (rus) or http://support.microsoft.com/kb/q133164/

Q: In application I use ActiveX control, I create distribution by using VFP Setup Wizard. After installation on the customer I receive an error: OLE error code 0x80040112: Appropriate license for this class not found. Whether it is possible to overcome it?а

A: see "INFO: OLE Control Licensing in Visual FoxPro" in MSDN also see "HOWTO: Register an ActiveX Control (.ocx) Manually".

Q: I have Windows NT, I try to do printing from RichTextBox Control, but it's not possible from CommonDialog Control to receive device context hDC property to transmit to first (in method SelPrint). In other words: whether it is possible to introduce an information from RichTextBox Control to printing?а

A: Hm... has looked... and really does not work... :-( However, try something as next:
#DEFINE C_DRVNAME "winspool"
DECLARE LONG CreateDC IN Gdi32.dll ;
  STRING @ lpszDriver, ; &&// driver name
  STRING @ lpszDevice, ; &&// device name
  STRING @ lpszOutput, ; &&// not used; should be NULL
  STRING @ lpInitData  &&// optional printer data
LOCAL nCntPrn
LOCAL ARRAY laPrinters[1,2]
nCntPrn = APRINTERS(laPrinters)
IF nCntPrn = 0
 RETURN .F.
ENDIF
LOCAL lcPrinter, lhDC
lcPrinter = laPrinters[1,1]
lhDC = CreateDC(C_DRVNAME, lcPrinter, NULL, NULL)
IF lhDC = 0
 RETURN .F.
ENDIF
ThisForm.Olecontrol1.Object.SelPrint(lhDC)
CLEAR DLLS
C_DRVNAME as I have understood from MSDN CreateDC() for Windows 95/98 there should be NULL. However at me NT too, and therefore "winspool"

Q: Whether I somehow can insert Internet Explorer into the VFP-form?а

A: Try to do something similarly to following:
#DEFINE C_URL	"http://vfpdmur.narod.ru/" &&- Insert your URL here

RELEASE ox
PUBLIC ox
ox = CreateObject("MyInternetExplorer")
IF TYPE('ox') = 'O' AND !ISNULL(ox)
	WITH ox
		.oWeb.Navigate(C_URL,,"_self")
		IF !.Visible
			.Visible = .T.
		ENDIF
	ENDWITH
ELSE
	MESSAGEBOX("Error in CreateObject('MyInternetExplorer')", 16, 'Error')
ENDIF

DEFINE CLASS MyInternetExplorer AS form
	ADD OBJECT oWeb AS CWebExp
	Caption = "My Internet Explorer"
	PROCEDURE Init
		WITH ThisForm
			.Width = SYSMETRIC(21)*3/4
			.Height = SYSMETRIC(22)*3/4
			.Resize()
		ENDWITH
	ENDPROC
	PROCEDURE Resize
		ThisForm.oWeb.resize()
	ENDPROC
ENDDEFINE

DEFINE CLASS CWebExp AS olecontrol
	OleClass = "Shell.Explorer"
	PROCEDURE Resize
		WITH This
			.Width = ThisForm.Width - 1
			.Height = ThisForm.Height - 1
		ENDWITH
	ENDPROC
	PROCEDURE Refresh
		NODEFAULT
	ENDPROC
ENDDEFINE

Q: The h-file with definition of constants for Excel 2000 is necessary Where it is possible to take?а

A: Where to take just for Excel 2000 I do not know, for Excel 97 is on http://www.universalthread.com However, there is still such utility "GetConstants - COM constants to .h file" on http://www.west-wind.com/files/getconstants.zip

Q: SelectOnEntry on MouseClick for TextBox how to do?а

A: Try execute KEYBOARD '{SHIFT+END}' in event MyTextBox.GotFocus()

Q: It is impossible to use DayBold() in ActivX Comctl2.MonthView.2, returns "Function argument value, type, or count is invalid (Error 11)". How to overcome?а

A: Try to use next code:
 
WITH ThisForm.Olecontrol1.Object 
	FOR lnCnt = 1 TO 42 
		.DayBold(TTOC(.VisibleDays(lnCnt))) = .T. 
	ENDFOR 
ENDWITH 
а
а
Hosted by uCoz