Datagrid problem

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Rob van der Sloot
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 78
Joined: Sat Apr 17, 2010 9:21 am

Datagrid problem

Post by Rob van der Sloot » Fri Nov 09, 2018 2:11 pm

I have made a big application with many datagrids.
There are 3 main stacks with each several substacks
In the mainstacks I use one substack as menubar, which hides when clicked on a line in one of the datagrids.
One of the datagrids in the menubar-stack is the same and manages the background. In one stack this works fine, but now I copied this datagrid to the next substack of the second mainstack. And now it does not work anymore. I don't understand what is wrong. Please help me out of this.

The code is quite simple and I use this form in many datagrids without any problem.
on mouseUp pBtnNum
if pBtnNum is 1 then
put the dgHilitedLines of group "dgBGDE" into theLine
put the dgDataOfLine[theLine] of group "dgBGDE" into theDataA
put theDataA["Col 1"] into tMenuItem
If tMenuItem = "None" then
set the backdrop to none
else
If tMenuItem = "Green" then
set the backdrop to 83,208,183
else
If tMenuItem = "Bleu" then
set the backdrop to 84,126,237
else
If tMenuItem = "Red" then
set the backdrop to 255,108,108
else
If tMenuItem = "Yellow" then
set the backdrop to 255,255,113
else
If tMenuItem = "Grey" then
set the backdrop to 192,192,192
end if
end if
end if
end if
end if
end if
end if
hide this stack
end mouseUp

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Datagrid problem

Post by Klaus » Fri Nov 09, 2018 2:33 pm

Dag Rob,

the problem is that we should not copy and paste any existing datagrid!
This leads to unexspected behaviour (non-working datagrids) as you experienced.
Don't ask me why, but that's the way it is.

So always create a new datagrid to be on the safe side.

Some scripting hints and please use the CODE tags -> </> at the tiop of this entry field after pasting your LC script here.

To make a script more readable and to avoid many, many nested IF THEN clauses use the SWITCH statment.
Your script:

Code: Select all

on mouseUp pBtnNum
   if pBtnNum is 1 then
      put the dgHilitedLines of group "dgBGDE" into theLine
      put the dgDataOfLine[theLine] of group "dgBGDE" into theDataA
      put theDataA["Col 1"] into tMenuItem
      If tMenuItem = "None" then
         set the backdrop to none
      else
         If tMenuItem = "Green" then
            set the backdrop to 83,208,183
         else
            If tMenuItem = "Bleu" then
               set the backdrop to 84,126,237
            else
               If tMenuItem = "Red" then
                  set the backdrop to 255,108,108
               else
                  If tMenuItem = "Yellow" then
                     set the backdrop to 255,255,113
                  else
                     If tMenuItem = "Grey" then
                        set the backdrop to 192,192,192
                     end if
                  end if
               end if
            end if
         end if
      end if
   end if
   hide this stack
end mouseUp
A bit modified:

Code: Select all

on mouseUp pBtnNum
   hide this stack
   if pBtnNum <> 1 then
      exit mouseup
   end if
   
   put the dgHilitedLines of group "dgBGDE" into theLine
   put the dgDataOfLine[theLine] of group "dgBGDE" into theDataA
   put theDataA["Col 1"] into tMenuItem
   
   switch tMenuItem
      case "None"
         set the backdrop to "none"
         break
      case  "Green" 
         set the backdrop to 83,208,183
         break
      case "Bleu"
         set the backdrop to 84,126,237
         break
      case "Red" 
         set the backdrop to 255,108,108
         break
      case "Yellow" 
         set the backdrop to 255,255,113
         break
      case "Grey" 
         set the backdrop to 192,192,192
         break
   end switch
end mouseUp
Best

Klaus

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Datagrid problem

Post by bogs » Fri Nov 09, 2018 4:06 pm

Klaus wrote:
Fri Nov 09, 2018 2:33 pm
To make a script more readable and to avoid many, many nested IF THEN clauses use the SWITCH statment.
I agree with the sentiment on code that looks like a giant >
But, you could also (just as a matter of style) get rid of a lot of the readability issues by formatting your if / then setup a little differently. For instance, the same code as listed above changes to this -

Code: Select all

on mouseUp pBtnNum
   if pBtnNum is 1 then
      put the dgHilitedLines of group "dgBGDE" into theLine
      put the dgDataOfLine[theLine] of group "dgBGDE" into theDataA
      put theDataA["Col 1"] into tMenuItem
      If tMenuItem = "Green" then
         set the backdrop to 83,208,183
      else If tMenuItem = "Bleu" then
         set the backdrop to 84,126,237
      else If tMenuItem = "Red" then
         set the backdrop to 255,108,108
      else If tMenuItem = "Yellow" then
         set the backdrop to 255,255,113
      else If tMenuItem = "Grey" then
         set the backdrop to 192,192,192
      else // "none" was selected...
         set the backdrop to none
      end if
   end if
   hide this stack
end mouseUp
...in which I simply moved the "none" selection to the bottom (if it isn't any of the other choices, it is the choice by default), and should be just as readable, I think. I could be wrong there though, I remember reading somewhere at some point that Lc either had problems with a LOT of switch/case or if/then statements, just can't remember which :P

Edit - In fact, thinking about it a bit more, you could really just change that to something like (for color selection) -

Code: Select all

put tMenuItem into tmpColor
if tmpColor is not "none" then set the backdrop to tmpColor
I didn't test the above, but you get the idea. It would work for any colorName in this list

Code: Select all

AliceBlue
AntiqueWhite
AntiqueWhite1
AntiqueWhite2
AntiqueWhite3
AntiqueWhite4
Aquamarine
Aquamarine1
Aquamarine2
Aquamarine3
Aquamarine4
Azure
Azure1
Azure2
Azure3
Azure4
Beige
Bisque
Bisque1
Bisque2
Bisque3
Bisque4
Black
BlanchedAlmond
Blue
Blue1
Blue2
Blue3
Blue4
BlueViolet
Brown
Brown1
Brown2
Brown3
Brown4
Burlywood
Burlywood1
Burlywood2
Burlywood3
Burlywood4
CadetBlue
CadetBlue1
CadetBlue2
CadetBlue3
CadetBlue4
Chartreuse
Chartreuse1
Chartreuse2
Chartreuse3
Chartreuse4
Chocolate
Chocolate1
Chocolate2
Chocolate3
Chocolate4
Coral
Coral1
Coral2
Coral3
Coral4
CornflowerBlue
CornSilk
CornSilk1
CornSilk2
CornSilk3
CornSilk4
Cyan
Cyan1
Cyan2
Cyan3
Cyan4
DarkBlue
DarkCyan
DarkGoldenrod
DarkGoldenrod1
DarkGoldenrod2
DarkGoldenrod3
DarkGoldenrod4
DarkGray
DarkGreen
DarkKhaki
DarkMagenta
DarkOliveGreen
DarkOliveGreen1
DarkOliveGreen2
DarkOliveGreen3
DarkOliveGreen4
DarkOrange
DarkOrange1
DarkOrange2
DarkOrange3
DarkOrange4
DarkOrchid
DarkOrchid1
DarkOrchid2
DarkOrchid3
DarkOrchid4
DarkRed
DarkSalmon
DarkSeaGreen
DarkSeaGreen1
DarkSeaGreen2
DarkSeaGreen3
DarkSeaGreen4
DarkSlateBlue
DarkSlateGray
DarkSlateGray1
DarkSlateGray2
DarkSlateGray3
DarkSlateGray4
DarkTurquoise
DarkViolet
DeepPink
DeepPink1
DeepPink2
DeepPink3
DeepPink4
DeepSkyBlue
DeepSkyBlue1
DeepSkyBlue2
DeepSkyBlue3
DeepSkyBlue4
DimGray
DodgerBlue
DodgerBlue1
DodgerBlue2
DodgerBlue3
DodgerBlue4
Firebrick
Firebrick1
Firebrick2
Firebrick3
Firebrick4
FloralWhite
ForestGreen
Gainsboro
GhostWhite
Gold
Gold1
Gold2
Gold3
Gold4
Goldenrod
Goldenrod1
Goldenrod2
Goldenrod3
Goldenrod4
Gray
Gray0
Gray1
Gray10
Gray100
Gray11
Gray12
Gray13
Gray14
Gray15
Gray16
Gray17
Gray18
Gray19
Gray2
Gray20
Gray21
Gray22
Gray23
Gray24
Gray25
Gray26
Gray27
Gray28
Gray29
Gray3
Gray30
Gray31
Gray32
Gray33
Gray34
Gray35
Gray36
Gray37
Gray38
Gray39
Gray4
Gray40
Gray41
Gray42
Gray43
Gray44
Gray45
Gray46
Gray47
Gray48
Gray49
Gray5
Gray50
Gray51
Gray52
Gray53
Gray54
Gray55
Gray56
Gray57
Gray58
Gray59
Gray6
Gray60
Gray61
Gray62
Gray63
Gray64
Gray65
Gray66
Gray67
Gray68
Gray69
Gray7
Gray70
Gray71
Gray72
Gray73
Gray74
Gray75
Gray76
Gray77
Gray78
Gray79
Gray8
Gray80
Gray81
Gray82
Gray83
Gray84
Gray85
Gray86
Gray87
Gray88
Gray89
Gray9
Gray90
Gray91
Gray92
Gray93
Gray94
Gray95
Gray96
Gray97
Gray98
Gray99
Green
Green1
Green2
Green3
Green4
GreenYellow
Honeydew
Honeydew1
Honeydew2
Honeydew3
Honeydew4
HotPink
HotPink1
HotPink2
HotPink3
HotPink4
IndianRed
IndianRed1
IndianRed2
IndianRed3
IndianRed4
Ivory
Ivory1
Ivory2
Ivory3
Ivory4
Khaki
Khaki1
Khaki2
Khaki3
Khaki4
Lavender
LavenderBlush
LavenderBlush1
LavenderBlush2
LavenderBlush3
LavenderBlush4
LawnGreen
LemonChiffon
LemonChiffon1
LemonChiffon2
LemonChiffon3
LemonChiffon4
LightBlue
LightBlue1
LightBlue2
LightBlue3
LightBlue4
LightCoral
LightCyan
LightCyan1
LightCyan2
LightCyan3
LightCyan4
LightGoldenrod
LightGoldenrod1
LightGoldenrod2
LightGoldenrod3
LightGoldenrod4
LightGoldenrodYellow
LightGray
LightGreen
LightPink
LightPink1
LightPink2
LightPink3
LightPink4
LightSalmon
LightSalmon1
LightSalmon2
LightSalmon3
LightSalmon4
LightSeaGreen
LightSkyBlue
LightSkyBlue1
LightSkyBlue2
LightSkyBlue3
LightSkyBlue4
LightSlateBlue
LightSlateGray
LightSteelBlue
LightSteelBlue1
LightSteelBlue2
LightSteelBlue3
LightSteelBlue4
LightYellow
LightYellow1
LightYellow2
LightYellow3
LightYellow4
LimeGreen
Linen
Magenta
Magenta1
Magenta2
Magenta3
Magenta4
Maroon
Maroon1
Maroon2
Maroon3
Maroon4
MediumAquamarine
MediumBlue
MediumForestGreen
MediumGoldenrod
MediumOrchid
MediumOrchid1
MediumOrchid2
MediumOrchid3
MediumOrchid4
MediumPurple
MediumPurple1
MediumPurple2
MediumPurple3
MediumPurple4
MediumSeaGreen
MediumSlateBlue
MediumSpringGreen
MediumTurquoise
MediumVioletRed
MidnightBlue
MintCream
MistyRose
MistyRose1
MistyRose2
MistyRose3
MistyRose4
Moccasin
NavajoWhite
NavajoWhite1
NavajoWhite2
NavajoWhite3
NavajoWhite4
Navy
NavyBlue
OldLace
OliveDrab
OliveDrab1
OliveDrab2
OliveDrab3
OliveDrab4
Orange
Orange1
Orange2
Orange3
Orange4
OrangeRed
OrangeRed1
OrangeRed2
OrangeRed3
OrangeRed4
Orchid
Orchid1
Orchid2
Orchid3
Orchid4
PaleGoldenrod
PaleGreen
PaleGreen1
PaleGreen2
PaleGreen3
PaleGreen4
PaleTurquoise
PaleTurquoise1
PaleTurquoise2
PaleTurquoise3
PaleTurquoise4
PaleVioletRed
PaleVioletRed1
PaleVioletRed2
PaleVioletRed3
PaleVioletRed4
PapayaWhip
PeachPuff
PeachPuff1
PeachPuff2
PeachPuff3
PeachPuff4
Peru
Pink
Pink1
Pink2
Pink3
Pink4
Plum
Plum1
Plum2
Plum3
Plum4
PowderBlue
Purple
Purple1
Purple2
Purple3
Purple4
Red
Red1
Red2
Red3
Red4
RosyBrown
RosyBrown1
RosyBrown2
RosyBrown3
RosyBrown4
RoyalBlue
RoyalBlue1
RoyalBlue2
RoyalBlue3
RoyalBlue4
SaddleBrown
Salmon
Salmon1
Salmon2
Salmon3
Salmon4
SandyBrown
SeaGreen
SeaGreen1
SeaGreen2
SeaGreen3
SeaGreen4
Seashell
Seashell1
Seashell2
Seashell3
Seashell4
Sienna
Sienna1
Sienna2
Sienna3
Sienna4
SkyBlue
SkyBlue1
SkyBlue2
SkyBlue3
SkyBlue4
SlateBlue
SlateBlue1
SlateBlue2
SlateBlue3
SlateBlue4
SlateGray
SlateGray1
SlateGray2
SlateGray3
SlateGray4
Snow
Snow1
Snow2
Snow3
Snow4
SpringGreen
SpringGreen1
SpringGreen2
SpringGreen3
SpringGreen4
SteelBlue
SteelBlue1
SteelBlue2
SteelBlue3
SteelBlue4
Tan
Tan1
Tan2
Tan3
Tan4
Thistle
Thistle1
Thistle2
Thistle3
Thistle4
Tomato
Tomato1
Tomato2
Tomato3
Tomato4
Transparent
Turquoise
Turquoise1
Turquoise2
Turquoise3
Turquoise4
Violet
VioletRed
VioletRed1
VioletRed2
VioletRed3
VioletRed4
Wheat
Wheat1
Wheat2
Wheat3
Wheat4
White
WhiteSmoke
Yellow
Yellow1
Yellow2
Yellow3
Yellow4
YellowGreen
Edit 2 - I also just noticed that you have the word "Bleu" mispelled on the menu item, it should be "Blue" :D
Image

Rob van der Sloot
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 78
Joined: Sat Apr 17, 2010 9:21 am

Re: Datagrid problem

Post by Rob van der Sloot » Fri Nov 09, 2018 10:17 pm

Thanks very much, I did'nt know about the datagrid not working when copied.
Does this also mean you can't copy the code as well?
I will put the switch structure in, I just forgot about it because its not a option menu button, where I do use it.

Thanks again
Rob

Rob van der Sloot
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 78
Joined: Sat Apr 17, 2010 9:21 am

Re: Datagrid problem

Post by Rob van der Sloot » Fri Nov 09, 2018 10:21 pm

Thanks very much, I did'nt know about the datagrid not working when copied.
Does this also mean you can't copy the code as well?
I will put the switch structure in, I just forgot about it because its not a option menu button, where I do use it.

Also thanks for the color setup
I will also try this option to make a long list of colors, my clients will be exited :o

Thanks again
Rob

jameshale
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 474
Joined: Thu Sep 04, 2008 6:23 am
Location: Melbourne Australia

Re: Datagrid problem

Post by jameshale » Fri Nov 09, 2018 11:21 pm

Datagrids are more than you see on the screen.
Each datagrid you place on your card/stack brings with it a template substack.
Simply copying a DG from one stack to another will not copy the required templates that were installed with your original DG instance.
So, either do as has been suggested and recreate thr DG in the second stack or use Zryip’s Data Grid Helper which has a DG cloning function made expressly for this purpose.

James

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Datagrid problem

Post by bogs » Fri Nov 09, 2018 11:30 pm

Rob van der Sloot wrote:
Fri Nov 09, 2018 10:21 pm
Also thanks for the color setup
Well, I can't exactly take a lot of credit for that, I just typed -

Code: Select all

put the colorNames
into the message box and, well... :D

You can do the same thing in code in your program, but I suspect the number of choices would then become somewhat overwhelming :twisted:
Image

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Datagrid problem

Post by Klaus » Fri Nov 09, 2018 11:53 pm

Hi Rob,
Rob van der Sloot wrote:
Fri Nov 09, 2018 10:17 pm
Does this also mean you can't copy the code as well?
of course not!

@James
There can also be problems if you copy/paste a datagrid in the same stack!


Best

Klaus

jameshale
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 474
Joined: Thu Sep 04, 2008 6:23 am
Location: Melbourne Australia

Re: Datagrid problem

Post by jameshale » Sat Nov 10, 2018 12:20 am

@klaus
There can also be problems if you copy/paste a datagrid in the same stack!
Indeed there can. Making DGH even handier :D

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Re: Datagrid problem

Post by quailcreek » Sat Nov 10, 2018 11:13 pm

What the first DG is created in a stack there is also a sub-stack which is automatically created. There is also a card created in that sub-stack which is linked to the new DG. Each subsequently created DG causes a new card in the sub-stack to be created and linked to the new DG. These cards contain the default code and data related to its DG. Therefore, when you copy/paste a DG, the card in the sub-stack which it is linked to does not get copied and that’s what causes problems.
Tom
MacBook Pro OS Mojave 10.14

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”