Page 1 of 1

Formatting DataGrid form

Posted: Tue Oct 23, 2012 3:14 pm
by cusingerBUSCw5N
My datagrid form works by coincidence - not because I know what I am doing. However, the label field (when the text is too long) is bleeding into the other fields.

I tried adjusting the width, but either it had no effect, or it messed up all the formatting for the form. I think it is because I am using that field to set the overall dimensions of the field rect - but since I really don't know what I'm doing, I can't fix it.

I really don't understand rects - and how many you need and what they're used for. In this datagrid, I set up 4 rects - in others I have done, I just used one. But once I got this one working, I didn't want to mess anything up...so forgive me if the bottom code is garbage.

So..here is the code that works, as long as I don't want to set any widths... The field "Label" is the one that I want to limit its width to the width of the rect minus the width of field webname (which is supposed to be in the top right corner).
Image

Code: Select all

-- This script defines the behavior of your data grid's custom template. This behavior
-- only applies to 'forms' and not 'tables'.

on FillInData pDataArray
    -- This message is sent when the Data Grid needs to populate
    -- this template with the data from a record. pDataArray is an
    -- an array containing the records data.
    -- You do not need to resize any of your template's controls in
    -- this message. All resizing should be handled in resizeControl.
    
   -- Example:
   set the text of field "label" of me to pDataArray["label 2"]
replace "pppz" with return in pDataArray["label 3"]
 set the text of field "col3" of me to pDataArray["label 3"]
   set the text of field "webname" of me to pDataArray["label 4"]
   set the text of field "date_added" of me to pDataArray["label 5"]
end FillInData

on LayoutControl pControlRect
    local theFieldRect
    ## label new field
    
set the left of field "label" of me to 55
put the rect of field "label" of me into theFieldRect2
put item 3 of pControlRect - 5 into item 3 of theFieldRect2
set the rect of field "label" of me to theFieldRect2

##resizes field to fit content

put item 2 of thefieldRect2 + the formattedheight of field "label" of me - the bottommargin of field "label" of me into item 4 of theFieldRect2
set the rect of field "label" of me to thefieldRect2


## webname new field
put the rect of field "webname" of me into theFieldRect3
put item 2 of pControlRect +1 into item 2 of theFieldRect3
put item 3 of pControlRect -5 into item 3 of theFieldRect3
set the rect of field "webname" of me to theFieldRect3

##resizes field to fit content

put item 2 of thefieldRect3 + the formattedheight of field "webname" of me - the bottommargin of field "webname" of me into item 4 of theFieldRect3
set the rect of field "webname" of me to thefieldRect3

## date_added new field
set the top of field "date_added" of me to the bottom of field "webname" of me
put the rect of field "date_added" of me into theFieldRect4
put item 2 of pControlRect +15 into item 2 of theFieldRect4
put item 3 of pControlRect -5 into item 3 of theFieldRect4
set the rect of field "date_added" of me to theFieldRect4

##resizes field to fit content

put item 2 of thefieldRect4 + the formattedheight of field "date_added" of me - the bottommargin of field "date_added" of me into item 4 of theFieldRect4
set the rect of field "date_added" of me to thefieldRect4

##col3 expands field to fill width

set the top of field "col3" of me to the bottom of  field "label" of me +10
put the rect of field "Col3" of me into theFieldRect
put item 3 of pControlRect - 5 into item 3 of theFieldRect
set the rect of field "col3" of me to theFieldRect

##resizes field to fit content

put item 2 of thefieldRect + the formattedheight of field "col3" of me - the bottommargin of field "col3" of me into item 4 of theFieldRect
set the rect of field "col3" of me to thefieldRect

##update the bounding rect....

put item 4 of theFieldRect into item 4 of pControlRect

set the rect of graphic "background" of me to pControlRect
                                                                                                                                                                                                                                                                    
end LayoutControl


on ResetData
    -- Sent when data is being emptied because the control is no longer being used to display data
    set the text of field "Label" of me to empty
end ResetData


on PreFillInData
    -- Sent right before new data is going to replace existing data in the control
end PreFillInData


setprop dgHilite pBoolean
    -- This custom property is set when the highlight of your custom template has
    -- changed. By default the "Background" graphic will be highlighted for you. 
    -- You only add script here if you want to further customize the highlight.
    
    -- Example:
    if pBoolean then
        set the foregroundColor of me to the dgProp["hilited text color"] of the dgControl of me
    else
        set the foregroundColor of me to empty
    end if
end dgHilite


getprop dgDataControl
    -- Required by library so that it can locate your control.
    return the long ID of me
end dgDataControl


on mouseDoubleUp pMouseBtnNum
    local theKey
  
    pass mouseDoubleUp
end mouseDoubleUp
Thank you.