MouseUp code execution

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
francof
Posts: 237
Joined: Fri Apr 11, 2014 10:51 am

MouseUp code execution

Post by francof » Wed Oct 01, 2014 3:14 pm

Hi all,

I have, another, doubt on Scrollbars:
using a breakpoint into the mouseUp script of a datagrid, I have observed that the code runs also when I move between lines. without click on a line.
nothing in data shown change but, is it a normal behavior? is it possible to avoid?

best regards
franco

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: MouseUp code execution

Post by Klaus » Wed Oct 01, 2014 3:20 pm

Please post the doubtful code!

francof
Posts: 237
Joined: Fri Apr 11, 2014 10:51 am

Re: MouseUp code execution

Post by francof » Wed Oct 01, 2014 3:40 pm

Hi Klaus,

when I said:
....the code runs also when I move between lines.
I meant, using vertical scrollbar, of course.

anyway:

Code: Select all

on mouseUp                           --popola i campi con i dati del vino selezionato nella grid
   local tLineNumber
   
   --                                 ## Prepare to access custom property:
   put the dghilitedlines of grp "dgViniViti" into tLineNumber 
   set linedel to numtochar(2)
   
   put the cAllItems of group "dgViniViti" into tArray    
   put tArray[4] into tAllItems4
   put tArray[5] into tAllItems5
   put tArray[6] into tAllItems6
   put tArray[7] into tAllItems7
   put tArray[9] into tAllItems9
   put tArray[11] into tAllItems11
   
   --                        -- visualizza  i dati nei campi del gruppo grpViniVitigno
   put GetDataOfLine(tLineNumber, "Vino") into fld "fldVinoViti"
   put line tLineNumber of tAllItems4 into fld "fldAlcolMinViti"
   put line tLineNumber of tAllItems5 into fld "fldUvaggioViti"
   put line tLineNumber of tAllItems6 into fld "fldAltreTipolViti"
   put line tLineNumber of tAllItems7 into fld "fldConsumoViti"
   put line tLineNumber of tAllItems9 into fld "fldAffinamViti"
   put line tLineNumber of tAllItems11 into fld "fldNoteViniViti"
end mouseUp
best
franco

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: MouseUp code execution

Post by Klaus » Wed Oct 01, 2014 3:44 pm

Hi Franco,

please also post the rest of the (datagrid behavior) script.


Best

Klaus

francof
Posts: 237
Joined: Fri Apr 11, 2014 10:51 am

Re: MouseUp code execution

Post by francof » Wed Oct 01, 2014 9:02 pm

Hi Klaus,

my grid is Table style... not sure what do you mean, may be this script:

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 1"]
end FillInData


on LayoutControl pControlRect
    local theFieldRect
    
    -- This message is sent when you should layout your template's controls.
    -- This is where you resize the 'Background' graphic, resize fields and 
    -- position objects.
    -- For fixed height data grid forms you can use items 1 through 4 of pControlRect as
    -- boundaries for laying out your controls.
    -- For variable height data grid forms you can use items 1 through 3 of pControlRect as
    -- boundaries, expanding the height of your control as needed.
        
    -- Example:
    put the rect of field "Label" of me into theFieldRect
    put item 3 of pControlRect - 5 into item 3 of theFieldRect
    set the rect of field "Label" of me to theFieldRect
    
    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
    
    -- Example of how to edit the contents of a field.
    -- By passing the index of the record associated with copy of this template being displayed and
    -- a key (array key) the data grid will automatically save the changes the user
    -- makes and refresh the UI by calling FillInData and resizeControl.
    if pMouseBtnNum is 1 then
        if the dgProps["allow editing"] of the dgControl of me then
            switch the short name of the target
                case "Label"
                    put "Label 1" into theKey
                    EditFieldText the long ID of the target, the dgIndex of me, theKey
                    break                 
            end switch
        end if
    end if
    
    pass mouseDoubleUp
end mouseDoubleUp
franco

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: MouseUp code execution

Post by Klaus » Wed Oct 01, 2014 9:16 pm

Hi Franco,

thank you, looks OK!?

Sorry, no idea what is going on there, but that should
of course not happen when you simply scroll the group.


Best

Klaus

francof
Posts: 237
Joined: Fri Apr 11, 2014 10:51 am

Re: MouseUp code execution

Post by francof » Thu Oct 02, 2014 3:53 pm

ciao Klaus,
Klaus wrote:Hi Franco,

thank you, looks OK!?

Sorry, no idea what is going on there, but that should
of course not happen when you simply scroll the group.


Best

Klaus
This worries me a bit :(
if, you or someone else, want to take a look at this simple code
DataGrid.rar
(4.23 KiB) Downloaded 202 times
it's a new project only a grid with 3 lines of data. also with the scrollbars grayout, when click on them, the code runs.
thanks for your time

franco

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: MouseUp code execution

Post by Klaus » Thu Oct 02, 2014 4:36 pm

Hi Franco,

aha, now I get it! :D

Since the GROUP has this script and a datagrid is a group of grouped grouped groups etc.
we need to check if the mouseclick has occured in the relevant part of the datagrid!

Add something like this and it should work out fine:

Code: Select all

on mosueup

   ## Looks like the scrollbars are (part of) this -> graphic "dgBackground"
   if the short name of the target = "dgBackground" then
      exit mouseup
   end if
  ## Continue with the rest of the script here...
end mouseup
Best

Klaus

francof
Posts: 237
Joined: Fri Apr 11, 2014 10:51 am

Re: MouseUp code execution

Post by francof » Thu Oct 02, 2014 5:18 pm

Klaus wrote:Hi Franco,

aha, now I get it! :D

Since the GROUP has this script....
do you refer to the mouseUp script?

dgBackground don't works: code still runs. I have used this:

Code: Select all

 if the short name of the target = "dgHScrollbar" or the short name of the target = "dgScrollbar" then
      exit mouseup
end if
and more, there are also a "dgCornerPiece" (the square space, in the lower left corner of the grid, between the scrollbars :lol:
But, it is a normal behavior of the grid? using a mouseUp script, or I'm special?
I mean, if I want to do something at the click of the mouse on a row of a grid, and I've scrollbars, should I expect this? no one before me have used this handler?

thanks again, ciao
franco

Post Reply