Wiki Home

ex Grid


Namespace: Wiki
exGrid is an ActiveX grid control by Exontrol Software, Inc.

exGrid can be used with VFP 3.0 and above. The information below was mostly gathered during development in VFP 9.0, and may need to be "tweaked for earlier versions of VFP. It has some very unique features and acts almost as much like a Tree View control as a Grid control. One cool feature is the built in ability to handle multiple embedded ActiveX controls. This means you can create grid hierarchies, insert calendars, web pages, Word/Excel docs, maps, images, etc. and they appear as part of your grid. Another cool thing is their documented support for VFP!

exGrid is part of the extensive "exSuite" of controls by Exontrol.

Main Site: http://www.exontrol.com
exGrid FAQ: http://www.exontrol.com/faq.jsp?product=exgrid
exGrid Release Notes: http://www.exontrol.com/notes.jsp?product=exgrid
General FAQ: http://www.exontrol.com/sg.jsp?content=support/faq


Custom VFP exGrid Class (exVGrid): ftp://66.132.144.112/VFP/

I (Paul James) have created a custom VFP 9.0 class that wraps much of the exGrid control functionality. Download the exVGrid.zip from the FTP site listed above.
The zip file contains:
The classes/screen will work with earlier version of VFP with some modifications. Prior to VFP 9.0, VFP was not able to handle the "hItem" data type (Long Unsigned Integer I think). VFP fires an "Invalid Subscript Range" error when it tries to process a number greater than 65000. Since, the HITEM is a long value that most of the time exceeds 65000, Exontrol added a property in the control that could accept the "hItem" for VFP, it is called "DefaultItem". Prior to v9, you have to use this property instead of using a VFP variable.

So, when working with exGrid in version of VFP prior to 9.0, you must do something like the following:
   with thisform.exGrid
      .Items.DefaultItem = .Items.AddItem("Item 1")
      .Items.CellImage(0,1) = 2
   endwith


In VFP 9.0 (and later), you can do this:
   with thisform.exGrid
      x = .Items.AddItem("Item 1")
      .Items.CellImage(x,1) = 2
   endwith


Printing
Printing/Previewing a grid "exactly" as it appears on the screen is as easy as dropping the included exPrint control on your form, then putting this code behind a commandbutton:
   thisform.exPrint1.PrintExt = thisform.exGrid1.Object
   thisform.exPrint1.Preview()


*Notice I used the "Object" property to get around the OLE object that VFP creates.
*Note: The Print control will not recurse into contained ActiveX controls (child grids) and print them.

See the Wiki topic Ole Objects for more info on this.

Adding Items/Rows
*An "Item" is a "Row" in database terminology.

Accessing Items, Columns, and Cells
First Item/Row
Thisform.Grid1.Items(0)
First Column
Thisform.Grid1.Columns(0)
First Cell of the First Item
Each of the following lines of code are equivalent:
Thisform.Grid1.Items.ItemCell(Thisform.Grid1.Items(0), 0)
Thisform.Grid1.Items(0), 0
Thisform.Grid1.Items(0)
Thisform.Grid1.Items.ItemByIndex(0)
Thisform.Grid1.Items.ItemByIndex(0), 0
Thisform.Grid1.Items(0), Thisform.Grid1.Columns(0)
So, any of the above could be used in the following:
Thisform.Grid1.Items._AnyCellProperty_(_AnyOfTheAbove_) = .T.
i.e.
Thisform.Grid1.Items.CellHasButton(Thisform.Grid1.Items(0), 0) = .T.


Changing Item properties or contents
Notice, the Grid does not have an "Item" property to refer to a single item (ie Grid1.Items.Item).
Instead, you to establish a "default" item as any single item from the Grid.Items collection (ie Grid1.Items.DefaultItem).
Once the "default" item is set, you do not need to reference it explicitly.
Grid1.Items.DefaultItem = Grid1.Items(0) &&Existing Item
--or--
Grid1.Items.DefaultItem = Grid1.Items.AddItem("Test") &&Add a new item and make it the "default".
--or--
Grid1.Items.DefaultItem = Grid1.Items.InsertItem(i,,"Child") &&Add a new child item and make it the "default".
--or--
lnItem = Grid1.Items.AddItem("Test") &&Add a new item, assign it to a variable.
Grid1.Items.DefaultItem = lnItem &&Set the default item to the variable.

When a new item is added, the Add Item() or InsertItem() methods return a "handle" (unsigned Long Integer).
This "handle" is basically, an offset into the array of Grid.Items.
The "handle" can be used to specify an Item in the Items collection.
h = Grid1.Items.AddItem("Test") &&Set the Handle
Grid1.Items.CellValue(h, 1) = "Simple Text" &&Use the Handle

Note that every "method" in the Grid.Items collection has the same 1st parameter: Item
Item = A (long Integer) "handle" pointing to a specific Item in the Grid.Items collection.
If you leave out the "Item" parameter, or use zero (0), you will get the "DefaultItem".

*Note that all of the "Cell methods" in the Grid.Items collection have the same 2nd Parameter: ColIndex
ColIndex = An integer representing the "column" or "cell" you want to access.
If you leave out the this parameter, or use zero (0), you will get the first column.

Cells
Assigning Values/Data to Cells:
Add Item() or InsertItem() methods, usually specify the value for the 1st "cell" in a "row/item".
Grid1.Items.DefaultItem = Grid1.Items.AddItem("Item 1 NEW! HTML Formatting Suport")

CellValue
Specifies the "value" for cells in additional columns.
Grid1.Items.CellValue(0,0) = "Value"

CellData
Associates "user data" with a cell.

CellImage
Value that indicates the index of the "icon" (16x16 size) in the grid's "Images Collection".
Grid1.Items.CellImage(0,0) = 1

CellPicture
Used to display larger sized images in a cell
Gird1.Items.CellPicture(0,0) = Load Picture("mypic.gif")

Additional Cell Properties:
CellState
Affects only checkbox/radio cells. 1=Checked, 0=UnChecked, 2=Partially Checked
Grid1.Items.CellState(0,0) = 1

CellHasCheckBox/CellHasRadioButton
Place a Checkbox or Radiobutton in a cell.
Grid1.Items.CellHasCheckBox(0,0) = .t.
Grid1.Items.CellHasRadioButton(0,0) = .t.

CheckImage/RadioImage
Specifies the images to use if a cell is a checkbox or radiobutton.
Grid1.Items.CheckImage(0) = 5

CellSingleLine
Indicates whether the cell uses one line or multiple lines (if needed).
Grid1.Items.CellSingleLine(0,0) = .f.

CellBold(0,0) = .t.
CellItalic(0,0) = .t.
CellEditor(0,0) - Editor specific to one cell, overrides the Column.Editor

Columns
.Columns(0).HeaderImage = 1
.Columns(0).HeaderImageAlignment = 2
.Columns(0).Editor.EditType - Specifies the "Editor Type" for this Column
0 = None (text only)
1 = EditType (multi-function text editor)
2 = DropDownType
3 = DropDownListType
4 = SpinType
5 = MemoType (dropdown extended text editor)
6 = CheckListType
7 = DateType (calendar dropdown)
8 = MaskType (masked input)
9 = ColorType (extended color picker)
10 = FontType (font picker)
11 = PictureType (display picture)
12 = ButtonType
13 = Progress Bar Type
14 = PickEditType (pick list user can edit)
15 = LinkEditType (editable web address)
16 = UserEditorType (any ActiveX control)
17 = ColorListType (simple color picker)
18 = MemoDropDownType (scrollable text editor)
19 = CheckValueType (displays checkbox)
20 = SliderType (puts a slider in the cell)



Items
.Items.ItemForeColor(0) = 0
.Items.ItemBackColor(0) = 255
.Items.ItemHeight(0) = 44
.Items.ExpandItem(0) = .t.
Child grid Column/Item access:
.Items.ItemObject(0).Columns.Add("Column added at runtime")
.Items.ItemObject(0).Items.AddItem("Item added at runtime")



Code Examples:

Download the exVGrid Class and Sample form from: ftp://66.132.176.206/VFP/



The following is an example of a very simple one-column grid with manually inserted rows:
Application.AutoYield = .f.  &&Allow exGrid to capture events.

Local oFont as Object, oGrid as Object, oChild as Object, iChild as Long, iItem as Long
Store .NULL. to oFont, oGrid, oChild
Store 0 to iChild, iItem

oFont = CreateObject("StdFont")  &&Font Object, used to set grid font properties.
oGrid = thisform.exGrid1

*Setup Main Grid appearance.
with oGrid
	.BeginUpdate

	oFont.Name = "Tahoma"
	oFont.Bold = .F.
	oFont.Size = 8
	.Font = oFont

	.SortOnClick		= exNoSort		&&Disable user sorting on header click.
	.LinesAtRoot 		= .f.
	.DefaultItemHeight 	= 16
	.ScrollBySingleLine = .t.
	.MarkTooltipCells 	= .f.
	.SelForeColor 		= RGB(0,0,0)
	.SelBackColor 		= RGB(240,240,240)
	.BackColor 			= RGB(255,255,255)
	.ForeColor 			= RGB(0,0,0)

	*Add a column
	.Columns.Add("")
	.Columns(0).Alignment			= exLeftAlignment		&&Align Cells in Column.  0=Left, 1=Center, 2=Right
	.Columns(0).HeaderAlignment		= exCenterAlignment		&&Aligns the caption inside the column header.  0=Left, 1=Center, 2=Right
	.Columns(0).HeaderBold 			= .F.
	.Columns(0).HTMLCaption			= "Invoice # 12345"
	.Columns(0).Editor.EditType 	= exReadOnly			&&No Editor

	.EndUpdate
EndWith

*Insert records into grid.
oGrid.BeginUpdate
Select myTable
Go top
Do While !Eof()
	iItem = oGrid.Items.AddItem(Alltrim(myTable.myField))
   	Select MyTable
	skip
EndDo
oGrid.EndUpdate



Both eXGrid and eXList don't work in Virtual Mode under VFP9.0 SP1. VFP8 works great.


Contributors:
Paul James

Categories:
Category ActiveX
Category ActiveXControls
Category Third Party Tools
Category Third Party Products
Category Tools
( Topic last updated: 2007.01.19 12:31:21 AM )