Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Button & Combobox in Grid
Message
 
To
04/02/2003 12:12:39
N. Lea
Nic Cross Enterprises
Valencia, California, United States
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00748929
Message ID:
00749001
Views:
23
>I have seen many programs do this particular method. If a user is trying to create an invoice program, they have a grid. If there are no records, then they usually can see one button on the grid that says 'ADD' (usually in place of where the item code is). They click on the button and it appends a record, then shows a combo box for the item code in place of the button 'ADD'. The add button then moves down below that record so that the user can add another item. I attempted to modify the current control in the init method, but the no matter if I sparse the column or not the button would not show up, let alone the combobox. The text box was all I could see. Can anyone give any suggestions? Thanks!!

The thing is that VFP grid is not designed for this, however it in general it can be done.

The problem with the grid is that it can not show any controls if there are no records.

So, you have to have one extra record which should be considered "empty" by evaluating whatever condition (say, some ID field is empty). Then you may add the commandbutton and the combobox into the column (and optionally remove the default textbox). Then this column should have DynamicCurrentControl expression that will evaluate which control to show. For example: IIF(EMPTY(id),"command1","combo1")

Then in Add button Click() event you place the following code:
replace id with sys(2015)
append blank 
skip -1
thisform.grid1.refresh()
so you keep you "empty" record the last one (I have no indexes here - it is just a sample. So the "empty" record will show the "Add" button and others - the combobox.
You also need to take care about having only one "empty record" to show the button.

Here is the code for the sample form:
PUBLIC oform1

oform1=NEWOBJECT("form1")
oform1.Show
RETURN


	**************************************************
*-- Form:         form1 (c:\z\gridadd.scx)
*-- ParentClass:  form
*-- BaseClass:    form
*-- Time Stamp:   02/04/03 03:23:07 PM
*
DEFINE CLASS form1 AS form


	Top = 0
	Left = 0
	DoCreate = .T.
	Caption = "Form1"
	Name = "Form1"


	ADD OBJECT grid1 AS grid WITH ;
		ColumnCount = 3, ;
		Height = 226, ;
		Left = 12, ;
		Panel = 1, ;
		RecordSource = "test3", ;
		RowHeight = 21, ;
		Top = 12, ;
		Width = 348, ;
		Name = "Grid1", ;
		Column1.ControlSource = "test3.id", ;
		Column1.Name = "Column1", ;
		Column2.ControlSource = "test3.item_name", ;
		Column2.Sparse = .F., ;
		Column2.DynamicCurrentControl = ['iif(empty(id),"command1","combo1")'], ;
		Column2.Name = "Column2", ;
		Column3.ControlSource = "test3.quantity", ;
		Column3.Name = "Column3"


	ADD OBJECT form1.grid1.column1.header1 AS header WITH ;
		Caption = "Condition", ;
		Name = "Header1"


	ADD OBJECT form1.grid1.column1.text1 AS textbox WITH ;
		BorderStyle = 0, ;
		Margin = 0, ;
		ForeColor = RGB(0,0,0), ;
		BackColor = RGB(255,255,255), ;
		Name = "Text1"


	ADD OBJECT form1.grid1.column2.header1 AS header WITH ;
		Caption = "Item", ;
		Name = "Header1"


	ADD OBJECT form1.grid1.column2.combo1 AS combobox WITH ;
		RowSourceType = 1, ;
		RowSource = "Apples,Oranges,Grapes,Pears", ;
		Height = 24, ;
		Left = 25, ;
		SpecialEffect = 1, ;
		Style = 2, ;
		Top = 35, ;
		Width = 100, ;
		BorderStyle = 0, ;
		Name = "Combo1"


	ADD OBJECT form1.grid1.column2.command1 AS commandbutton WITH ;
		Top = 23, ;
		Left = 25, ;
		Height = 27, ;
		Width = 84, ;
		Caption = "Add", ;
		Name = "Command1"


	ADD OBJECT form1.grid1.column3.header1 AS header WITH ;
		Caption = "Quantity", ;
		Name = "Header1"


	ADD OBJECT form1.grid1.column3.text1 AS textbox WITH ;
		BorderStyle = 0, ;
		Margin = 0, ;
		ForeColor = RGB(0,0,0), ;
		BackColor = RGB(255,255,255), ;
		Name = "Text1"


	PROCEDURE command1.Click
		replace id with sys(2015)
		append blank 
		skip -1
		thisform.grid1.refresh()
	ENDPROC


ENDDEFINE
*
*-- EndDefine: form1
**************************************************
Sample table structure:
Structure for table:    C:\Z\TEST3.DBF
Number of data records: 1      
Date of last update:    02/04/2003
Code Page:              1252    
Field  Field Name      Type                Width    Dec   Index   Collate Nulls
    1  ID              Character              10                             No
    2  ITEM_NAME       Character              10                             No
    3  QUANTITY        Numeric                10                             No
** Total **                                   31
Anyway I would not do it this way. Why not just place Add button somewhere beside the grid?
Nick Neklioudov
Universal Thread Consultant
3 times Microsoft MVP - Visual FoxPro

"I have not failed. I've just found 10,000 ways that don't work." - Thomas Edison
Previous
Reply
Map
View

Click here to load this message in the networking platform