PDA

View Full Version : Fiilling a multi column grid



Pepe
13-Feb-2005, 06:43 PM
Hi,

I need to fill a multi-column grid and I don't seem to be using the
correct propertie. I managed to fill up properly the first row but I
keep getting errors when trying to fill the next rows.

What is the proper command to populate a multi-column grid with data?

TIA

--
José Guimarães [ pg@moose-software.com ]
Director
Moose Software
http://www.moose-software.com

Ian Telfer
13-Feb-2005, 08:52 PM
Pepe,

The following is the procedure I use;

1. Set Dynamic_Update_State Of iGridID To False //helps speed up the
display
2. Send delete_data to the grid,
3. Loop though the data, - send data to the grid. I use the following 2
procedure (from Vincent I think), Send DoAddCheckBoxItem & Send
DoAddTextItem
4. Send Paint
5. Set Dynamic_Update_State To True

// Description
// This procedure will add an item to the grid but will tell the
grid to
// show the item as checkbox and show selected or not.
//
// $Rev History
// 15-09-96 Module header created

//************************************************** **************************

Procedure DoAddCheckboxItem
Local Integer iItem

Send Add_Item Msg_None ""
Moveint (Item_Count (Self) - 1) To iItem
Set Checkbox_Item_State Item iItem To True
End_Procedure // DoAddCheckboxItem


//************************************************** **************************
// $Module type: PROCEDURE
// $Module name: DoAddTextItem
// $Author : VOO
// Created : 03-11-99 @ 21:10
//
// Description
// After adding an item we will make that the item cannot be changed.
//
// $Rev History
// 03-11-99 Module header created

//************************************************** **************************
Procedure DoAddTextItem String sValue
Local Integer iItem

Send Add_Item Msg_None sValue

Moveint (Item_Count (Self) - 1) To iItem
Set Entry_State Item iItem To False
End_Procedure // DoAddTextItem

HTH

Ian
Pepe Guimarães wrote:
> Hi,
>
> I need to fill a multi-column grid and I don't seem to be using the
> correct propertie. I managed to fill up properly the first row but I
> keep getting errors when trying to fill the next rows.
>
> What is the proper command to populate a multi-column grid with data?
>
> TIA
>

Oliver T. Nelson
14-Feb-2005, 03:25 PM
I use a grid subclass that I wrote that makes things much easier. It is attached.

OLIVER

Pepe Guimarães wrote:
> Hi,
>
> I need to fill a multi-column grid and I don't seem to be using the
> correct propertie. I managed to fill up properly the first row but I
> keep getting errors when trying to fill the next rows.
>
> What is the proper command to populate a multi-column grid with data?
>
> TIA
>


//************************************************** *************************
//*
//* Class: cTAPIGrid
//* Package Name: cTAPIGrid.pkg
//*
//************************************************** *************************

Use DFAllEnt.pkg

Class cTAPIGrid is a Grid

// Construct_Object: Object constructor.
Procedure Construct_object
Property integer piNumColumns 0
Property integer piCurrentColumn 0
Property integer piCurrentRow 0
Property boolean pbAllowEntry True
Property boolean pbMouseTracking FALSE
Property boolean Private.pbTrackMouse FALSE
Forward Send Construct_Object

// Define new Properties: Property {Type} {pxName} {initial_value}

// Create child objects

// Set property values:

End_Procedure

Procedure End_Construct_Object
forward send end_construct_object
end_procedure

// Create and augment procedure and functions

Procedure Set Line_Width integer iColumns integer iRows
set piNumColumns to iColumns
forward set line_width to iColumns iRows
end_procedure

Procedure Set Cell_Value integer iRow integer iColumn string sValue
set value item ((iRow * piNumColumns(self)+iColumn)) to sValue
end_procedure

function cell_value integer iRow integer iColumn returns string
string sValue
get value item ((iRow * piNumColumns(self)+iColumn)) to sValue
function_return sValue
end_function

Procedure Set Cell_Message integer iRow integer iColumn integer iMsg
set message item ((iRow * piNumColumns(self)+iColumn)) to iMsg
end_procedure

function cell_message integer iRow integer iColumn returns integer
integer iMsg
get message item ((iRow * piNumColumns(self)+iColumn)) to iMsg
function_return iMsg
end_function

Procedure Set Cell_BG_Color integer iRow integer iColumn integer iRGB
set Item_Color item ((iRow * piNumColumns(self)+iColumn)) to iRGB
end_procedure

function cell_BG_Color integer iRow integer iColumn returns integer
integer iRGB
get item_color item ((iRow * piNumColumns(self)+iColumn)) to iRGB
function_return iRGB
end_function

Procedure Set Cell_FG_Color integer iRow integer iColumn integer iRGB
set ItemTextColor item ((iRow * piNumColumns(self)+iColumn)) to iRGB
end_procedure

function cell_FG_Color integer iRow integer iColumn returns integer
integer iRGB
get itemTextColor item ((iRow * piNumColumns(self)+iColumn)) to iRGB
function_return iRGB
end_function

Procedure AddBlankRow
integer iCnt

for iCnt from 1 to (piNumColumns(self))
send add_item msg_none ""
loop
end_procedure

Procedure DoDeleteRow integer iRow
integer iNumColumns iStartItem iCnt iStopItem

get piNumColumns to iNumColumns
move (iRow*iNumColumns) to iStopItem
move (iStopItem+iNumColumns-1) to iCnt
while (iCnt >= iStopItem)
send delete_item iCnt
decrement iCnt
loop
end_procedure

Function RowCount returns integer
integer iNumColumns iItemCount

get piNumColumns to iNumColumns
get item_count to iItemCount
function_return (iItemCount/iNumColumns)
end_function

Procedure Add_Item integer iMsg string sVal
forward send add_item imsg sVal
if (not(pbAllowEntry(self))) set entry_state item (item_count(self)-1) to false
end_procedure

Procedure Set Current_Item integer iItem
forward set current_item to iItem
set piCurrentColumn to (Mod(iItem,piNumColumns(self)))
set piCurrentRow to (iItem / piNumColumns(self))
end_procedure

Function ItemFromCell integer iRow integer iColumn returns integer
function_return ((iRow * piNumColumns(self)+iColumn))
end_function

Procedure Set Current_Cell integer iRow integer iColumn
set current_item to (ItemFromCell(self, iRow, iColumn))
end_procedure

function CellFromItem integer iItem returns integer
function_return ( ((iItem / piNumColumns(self)) * 65536) + (Mod(iItem,piNumColumns(self))) )
end_function

function PackRowColumn integer iRow integer iColumn returns integer
function_return ((iRow * 65536) + iColumn)
end_function

function CellFromPoint Overloaded integer iY integer iX returns integer
boolean bHeaderVisible
integer iCellHeight iCnt iColumnWidth iTotalWidth
integer iColumn iRow

get header_visible_state to bHeaderVisible
// Need to support the header being turned on and off, for now
// no support though, presumed off.

move -1 to iColumn
for iCnt from 0 to (piNumColumns(self)-1)
get form_guiWidth item iCnt to iColumnWidth
add iColumnWidth to iTotalWidth
if (iX < iTotalWidth) move iCnt to iColumn
if (iX < iTotalWidth) break
loop
if (iColumn = -1) function_return 0 // if its still -1 then we are not within the testable boundaries of the grid

get form_guiheight item 0 to iCellHeight
move (iCellHeight-3) to iCellHeight
move ( (iY/iCellHeight) + hi(cellfromitem(self,top_item(self))) ) to iRow
if (iRow < 0) function_return 0

function_return ((iRow*65536)+iColumn)
end_function

function cell_coordinates integer iRowColumn returns integer
boolean bHeaderVisible
integer iCellHeight iTotalHeight iCnt iColumnWidth iTotalWidth
integer iTopRow iRow iColumn

get header_visible_state to bHeaderVisible
// Need to support the header being turned on and off, for now
// no support though, presumed off.

move (hi(iRowColumn)) to iRow
move (low(iRowColumn)) to iColumn

move (hi(cellfromitem(self,top_item(self)))) to iTopRow
subtract iTopRow from iRow

for iCnt from 0 to (iColumn-1)
get form_guiWidth item iCnt to iColumnWidth
add iColumnWidth to iTotalWidth
loop

get form_guiheight item 0 to iCellHeight
move (iCellHeight-3) to iCellHeight
for iCnt from 0 to (iRow-1)
add iCellHeight to iTotalHeight
loop

function_return ((iTotalHeight*65536)+iTotalWidth)
end_function

Function CellFromPoint OverLoaded string sPoint returns integer
integer iX iY

getbuff from sPoint at tPoint.x to iX
getbuff from sPoint at tPoint.y to iY

function_return (CellFromPoint(self, iY, iX))
end_function


End_Class // cTAPIGrid

Pepe
18-Feb-2005, 08:19 AM
Thanks for your answers. Solved it by sending:

send add_item to objectid msg_none ""
set value of objectid item myitemnumber to stringvalue

--
José Guimarães [ pg@moose-software.com ]
Director
Moose Software
http://www.moose-software.com