Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Custom Grid 1

Status
Not open for further replies.

Paco75

Programmer
Oct 11, 2001
239
US
Hi,

I want to create an object that looks like a grid. But the rows could be collapsible like in a treeview nodes and fields could be labels, textboxes, checkbox or combobox.

Maybe it already exist if you have any links that could help me achieve this (or if it already exist that would be awesome).

to give you an idea of what i want to do look at this picture the grid on the right is exactly what i need.


thanks
 
Thanks, that's exactly what i need!
 
Is it possible with native VFP grid to have, on same column, display in one row a checkbox and on the next row display a combobox for example?
 


look at the column's dynamiccurrentcontrol property.

you can add any number of controls to a column and then use this to choose which control is shown for each row based on some value.

e.g. .columm1.dynamiccurrentcontrol = [iif(myfield=1,"mycheckbox","mytextbox")]

n
 
Like nigel showed this feeature exists, but I doubt you will want to use it to create a layout as you showed initially. I'd rather go with ActiveX here.

As Nigel showed you will use an IIF expression to switch between two controls, as you need more for your layout you will need ICASE or even call into a grid method to use a CASE..ENDCASE to decide the control used for the row and column.

Are you good at HTML? Do you perhaps have written your onw html treeview? Then you could use your html and display it within a webbrowser control.

Bye, Olaf.
 
Ok here is a sample i made based on this example by Mike Gagnon


Code:
oForm=Createobject("myForm")
oForm.width = 440
oForm.AddObject('myGrid1','myGrid')
oForm.myGrid1.column1.header1.Caption = "Field"
oForm.myGrid1.column1.width = 100
oForm.myGrid1.column2.header1.Caption = "Value"
oForm.myGrid1.column2.width = 300
oForm.myGrid1.column2.Sparse = .F.
oForm.myGrid1.column2.AddObject("TextField1","TextField")
oForm.myGrid1.column2.AddObject("ComboBoxField1","ComboBoxField")
*!*	oForm.myGrid1.column2.AddObject("SpinnerField1","SpinnerField")
*!*	oForm.myGrid1.column2.AddObject("CheckBoxField1","CheckBoxField")
oForm.Show(1)

Define Class myForm As Form
    AutoCenter = .T.
    Procedure Load()
	    Create Cursor myCursor (fName C(20), fValue C(20), fType C(3))
	    Insert Into myCursor (fName,fValue,fType) Values ("MODEL","FORD MUSTANG","TXT")
	    Insert Into myCursor (fName,fValue,fType) Values ("CYLINDERS","6","CBO")
	    Insert Into myCursor (fName,fValue,fType) Values ("YEAR","2008","TXT")
	    Insert Into myCursor (fName,fValue,fType) Values ("TURBO","T","TXT")
	    Go Top
	Endproc
Enddefine

Define Class myGrid As Grid
    Visible = .T.
    ColumnCount = 2
    Width = 400
    Top = 20
    Left = 20
    RowHeight = 26
	Procedure Init()
	    With This
	        .column2.DynamicCurrentControl = "dynamic()"
	        This.Parent.LockScreen = .F.
	    Endwith
	Endproc
ENDDEFINE

Define Class TextField As TextBox
    Visible = .T.
    height = 26
    Procedure Click
	    This.Parent.Parent.Parent.LockScreen = .T.
	    This.Parent.Parent.Init()
	Endproc
ENDDEFINE

Define Class ComboBoxField As Combobox
    Visible = .T.
    Rowsourcetype = 1
    Rowsource = "4,6,8"
    Procedure Click
	    This.Parent.Parent.Parent.LockScreen = .T.
	    This.Parent.Parent.Init()
	Endproc
ENDDEFINE

DEFINE CLASS SpinnerField as Spinner 
    Visible = .T.
    height = 26
    Procedure Click
	    This.Parent.Parent.Parent.LockScreen = .T.
	    This.Parent.Parent.Init()
	ENDPROC
ENDDEFINE 

DEFINE CLASS CheckBoxField as CheckBox 
    Visible = .T.
    height = 26
    Procedure Click
	    This.Parent.Parent.Parent.LockScreen = .T.
	    This.Parent.Parent.Init()
	ENDPROC
ENDDEFINE 

Function Dynamic
	Do Case
		Case myCursor.fType = "TXT"
		    Return "TextField1"
		Case myCursor.fType = "CBO"
		    Return "ComboBoxField1"
*!*			Case myCursor.fType = "SPN"
*!*			    Return "SpinnerField1"
*!*			Case myCursor.fType = "CHK"
*!*			    Return "CheckBoxField1"
	Endcase
Endfunc

The idea is to show a record in a grid and allow different type of input like checkbox, combobox to show/set values of the record.

I got a problem when the object has a value of different type than a string... like checkbox and spinner. Can i trap the value and convert it to a string then reconvert it to the component value?
 
Hi Olaf,

Yeah maybe i will go with the already done activeX component Nigel suggested. But before i buy it i want to see if it is possible to do this in native VFP...
 
>I got a problem when the object has a value of different type
>than a string... like checkbox and spinner.

That's why a foxpro grid won't be as flexible as an ActiveX grid/treeview. It's meant to show a table only, which has a type per column, and not many. A grid is no excel sheet or such a table, where each cell is individual, an ActiveX GRid typically can be used that way.

You can go one extreme to not be bound to column types: Set your grid to 1 column only, set the recordsource, so creates a row per record, but unset the column1.controlsource by explictly setting it to [=""] in the property editor.

To use this one column for any type of row design, develop several containers for each record type and layout the controls etc. you want for the rowtype.

Bye, Olaf.

 
I forgot to say:

...and finally: Use those record containers via column1.dynamiccurrentcontrol, which kind of makes it dynamiccurrentrow

Bye, Olaf.
 
Paco,

I'm coming a bit late to this discussion.

But I'd like to endorse Nigel's suggestion that you look at the Codejock report control. Nigel recommended this product to me a couple of years ago, and I've now used it successfully in two projects.

The Codejock control will do everything what you want, and more. But be warned: the documentation is terrible, and the support is luke-warm (at least, that was the case with the version that I purchased; it might have improved since then).

You asked if the native VFP grid allows you to have different controls in different rows. The way to do that is with the DynamicCurrentControl property, as per Olaf's suggestion. You can find an example here: Conditional formatting in a Visual FoxPro grid.

That example shows how you can place different images in different rows, but the same approach is fine with combo boxes, checkboxes and the like.

Let us know what you eventually decide.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Hi Mike,

I think i will go with codejock extreme property grid, but when i go on their website they got only one tutorial... so im not yet sure :S
 
I developed a custom grid a few years back for VFP6. I used VFP classes and created an object I dropped on the form. It had sources for data, settings for scrolling, etc.

My goals was to create a grid for narrow columns what went down a short distance, then wrapped to the top of the column in the middle, then wrapped to the top of the column on the right (assuming three would fit, right/left if two, more if more), etc.

It worked great. Users loved it. More narrow column data on a small screen, and it was all relational. I also set it up so the label that was displayed could be clicked on and an editbox appeared so they could edit the contents. I had custom save algorithms, etc. It was nice.

Took a bit of coding, but the end product was nice. Don't have the source code rights or I'd give it to you as a template. Just wanted to tell you it is possible, and it is fast, and it does work nicely even if done entirely in VFP with custom objects.

Best regards,
Rick C. Hodgin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top