First problems...datagrid

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

glpunzi
Posts: 57
Joined: Sun Nov 28, 2010 5:50 pm
Contact:

First problems...datagrid

Post by glpunzi » Thu Dec 02, 2010 9:42 pm

Preamble
I'm trying to do something to take a lookt at how to work with LiveCode. My intention, is to create a database, fill with some data, and show it in 2 grids. Then, when I select in 1st grid (customers), in second grid, only bills from this customers must be shown. In Bills Grid, if TotalBill column is between 0 and 300, column color must be red, 300 and 700 orange, >700 green. Easy, really? not for me :oops:

Problems/Doubts

I'm following SqliteSample from http://www.runrev.com/developers/lesson ... le-sqlite/

In this sample, is not used Datagrid, and my code fails :S
I can't find where can I change the color of a column in some row (color reference in Preamble)
I saw somewhere, something like a Database option in Inspector, and a SQL Builder, but I can't find it.

Working under Fedora 14 32bits.

Some help please?

Note: HipermegaNoob Stack Attached, if you see inside, please, don't be cruel with me :roll:
Attachments
TestSqlite.livecode.zip
(7.6 KiB) Downloaded 297 times

glpunzi
Posts: 57
Joined: Sun Nov 28, 2010 5:50 pm
Contact:

Re: First problems...datagrid

Post by glpunzi » Fri Dec 03, 2010 6:01 pm

Well...13 view, no downloads.

I had no success

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

Re: First problems...datagrid

Post by Klaus » Fri Dec 03, 2010 8:39 pm

Hola Guiseppe,

believe me: whining will not force any more answers! 8)
This forum is completely driven by volunteers, so you can force noone to answer your questions fast or at all!

OK, I took a look and found this in the button "DataToGrids", which gave me an error after clicking!
Please change the last line:
##put tList into "Customers Grid" (You cannot put the contents of a variable into a STRING!)
to
set the dgText of grp "Customers Grid" to tList
And your data will appear in the datagrid, very basic stuff!

I think you will have to learn the basics before you should try to do what you said in your posting above (and all this IS in fact in the PDF)!
Please check this url, download the PDF and start exploring "DataGrids", which is definitively advanced stuff!
http://lessons.runrev.com/spaces/lesson ... s/datagrid

Be patient, make small steps and you will succeed in the end!
Rome was not build in a day :)


Best

Klaus

ibe
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 61
Joined: Sun Oct 04, 2009 12:15 pm

Re: First problems...datagrid

Post by ibe » Fri Dec 03, 2010 9:23 pm

I noticed the same flaw as Klaus when filling in the data. Now that you have the data in the first table you should do an SQL query when the user selects a row in the customer table:

Code: Select all

on selectionChanged pHilitedIndex, pPrevHilitedIndex
   put the dgDataOfIndex [ pHilitedIndex ] of me into theSelDataA
   showCustomersBills theSelDataA["customerID"]
end selectionChanged
where in the showCustomerBills you do the query to fill in the second grid. To highlight a specific number you might want to have a look at the sample on the LiveCode site:
http://lessons.runrev.com/spaces/lesson ... to-a-Cell-

Basically you just have to intercept the filling in of the data for that grid with something like this:

Code: Select all

on FillInData pData
   -- This message is sent when the Data Grid needs to populate
   -- this template with the column data. pData is the value to be displayed.
   if the dgColumn of me is "TotalBill" then
      if pData < 300 then
         set the backgroundColor of me to 255, 0, 0
      else if pData < 701 then
         set the backgroundColor of me to 255, 127, 0
      else
         set the backgroundColor of me to 0, 255, 0
      end if 
   end if
end FillInData
or of course if you don't want to change the column color but the text in the column use

Code: Select all

      set textColor of me to 255, 0, 0
My 2 cents,

Ismo

glpunzi
Posts: 57
Joined: Sun Nov 28, 2010 5:50 pm
Contact:

Re: First problems...datagrid

Post by glpunzi » Fri Dec 03, 2010 9:44 pm

Thanks a lot to both.

Tomorrow I will follow your advices.

P.S.
believe me: whining will not force any more answers
I suppose it, but I wanted to try :D sorry for thath :oops:

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

Re: First problems...datagrid

Post by Klaus » Fri Dec 03, 2010 10:58 pm

:D

glpunzi
Posts: 57
Joined: Sun Nov 28, 2010 5:50 pm
Contact:

Re: First problems...datagrid

Post by glpunzi » Sat Dec 04, 2010 12:35 pm

ibe wrote:I noticed the same flaw as Klaus when filling in the data. Now that you have the data in the first table you should do an SQL query when the user selects a row in the customer table:

Code: Select all

on selectionChanged pHilitedIndex, pPrevHilitedIndex
   put the dgDataOfIndex [ pHilitedIndex ] of me into theSelDataA
   showCustomersBills theSelDataA["customerID"]
end selectionChanged
where in the showCustomerBills you do the query to fill in the second grid. To highlight a specific number you might want to have a look at the sample on the LiveCode site:
http://lessons.runrev.com/spaces/lesson ... to-a-Cell-
This works, ;)
Basically you just have to intercept the filling in of the data for that grid with something like this:

Code: Select all

on FillInData pData
   -- This message is sent when the Data Grid needs to populate
   -- this template with the column data. pData is the value to be displayed.
   if the dgColumn of me is "TotalBill" then
      if pData < 300 then
         set the backgroundColor of me to 255, 0, 0
      else if pData < 701 then
         set the backgroundColor of me to 255, 127, 0
      else
         set the backgroundColor of me to 0, 255, 0
      end if 
   end if
end FillInData
or of course if you don't want to change the column color but the text in the column use

Code: Select all

      set textColor of me to 255, 0, 0
My 2 cents,

Ismo
This not works.

I tried to put FillinData directly on the Datagrid script, throug a button like datagrid manual said, throug Column Behaviour button in Datagrid property panel, and with and without this line before (you don't mentioned, and I don't know is needed, but seems like is it needed) "set the text of field 1 of me to pData"

And any of this colours me the datagrid column.

Otherwise, this is not important right now. I only wanted to try some master-detail "real example", and now..works

Thanks a lot ;)

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

Re: First problems...datagrid

Post by Klaus » Sat Dec 04, 2010 2:13 pm

Hola Guiseppe,

1. the parameter "pData" in "fillinData" is an ARRAY
2. your are not addressing a FIELD
3. you do not fill the field in the handler which is also necessary!

All this is described in the examples in the PDF/DataGrid docs.

So this:

Code: Select all

...
if pData < 300 then
      set the backgroundColor of me to 255, 0, 0
else if pData < 701 then
      set the backgroundColor of me to 255, 127, 0
else
      set the backgroundColor of me to 0, 255, 0
end if
...
will always end with the backgroundcolor set to 0,255,0 and empty fields!

You need something like this:

Code: Select all

...
if pData["TotalBill"] < 300 then
   put 255,0,0 into tBColor
else if pData < 701 then
   put 255,127,0 into tBColor
else
   put 0, 255, 0 into tBColor
end if
set the backgroundColor of FIELD "TotalBill" of me to tBColor
set the text of fld "TotalBill" of me to pData["TotalBill"]
...
Using and filling a variable first and then setting the fields color to that variable will save some typing :)

I am not very experienced with DataGrids, so no guarantees here! 8)

Best

Klaus

ibe
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 61
Joined: Sun Oct 04, 2009 12:15 pm

Re: First problems...datagrid

Post by ibe » Sat Dec 04, 2010 3:36 pm

Sorry, should've tested it first. This works for me in version 4.5:

Code: Select all

on FillInData pData
   -- This message is sent when the Data Grid needs to populate
   -- this template with the column data. pData is the value to be displayed.
   set the text of me to pData

   if the dgColumn of me is "TotalBill" then
      if the text of me < 301 then
         set the backgroundColor of me to 255, 0, 0
      else if the text of me < 701 then
         set the backgroundColor of me to 255, 127, 0
      else
         set the backgroundColor of me to 0, 255, 0
      end if 
   end if
end FillInData
Hope it helps,

Ismo

glpunzi
Posts: 57
Joined: Sun Nov 28, 2010 5:50 pm
Contact:

Re: First problems...datagrid

Post by glpunzi » Tue Dec 07, 2010 11:47 am

Where you put this code?

I tried, and don't worked.

I can't explain more the error, because I'm not in front of my PC

ibe
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 61
Joined: Sun Oct 04, 2009 12:15 pm

Re: First problems...datagrid

Post by ibe » Tue Dec 07, 2010 2:26 pm

The code should go into the script of the default column behavior button. Please look at the sample on the LiveCode site:
http://lessons.runrev.com/spaces/lesson ... to-a-Cell-

Ismo

glpunzi
Posts: 57
Joined: Sun Nov 28, 2010 5:50 pm
Contact:

Re: First problems...datagrid

Post by glpunzi » Tue Dec 07, 2010 3:39 pm

I think I'm doing all the steps, and don't works.

Maybe don't works in Linux?
Attachments
TestSqlite.livecode.zip
(11.14 KiB) Downloaded 276 times

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: First problems...datagrid

Post by bangkok » Tue Dec 07, 2010 4:29 pm

Have a look on this stack.

It simulates what you want to do (different background color on datagrid lines, depending of the content of one specific column, here "status").

I was like you a few weeks ago : datagrids looked horribly complicated, even esoteric.

But once you've got the trick, then everything makes sense. :D Well actually, it's always like that, isn't it ?
Attachments
LETEST.zip
(5.95 KiB) Downloaded 293 times

glpunzi
Posts: 57
Joined: Sun Nov 28, 2010 5:50 pm
Contact:

Re: First problems...datagrid

Post by glpunzi » Thu Dec 09, 2010 1:26 pm

bangkok wrote:Have a look on this stack.

It simulates what you want to do (different background color on datagrid lines, depending of the content of one specific column, here "status").

I was like you a few weeks ago : datagrids looked horribly complicated, even esoteric.

But once you've got the trick, then everything makes sense. :D Well actually, it's always like that, isn't it ?
This works with the complete row.

I will check the code when have time.

Thanks a lot.

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

Re: First problems...datagrid

Post by Klaus » Thu Dec 09, 2010 1:39 pm

Hi all,

sorry if my post from "Sat Dec 04, 2010 2:13 pm" made a little confusion.
I completely overlooked that you were looking for a custom behaviour of a ROW.
My script was more generic for the complete datagrid.


Best

Klaus

Post Reply