A few small questions with my first data grid attempts..

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
Weaksafety
Posts: 17
Joined: Mon Aug 12, 2013 5:20 pm

A few small questions with my first data grid attempts..

Post by Weaksafety » Mon Jun 02, 2014 10:21 am

Hi!

I begun working on livecode a couple of weeks ago with very very little programming experience (self taught some ruby, lasted a couple of months).

I'm trying to familiarize with the data grid. I succeeded in creating a few controls to populate a DG table, however I can't find a way to edit a single row.

What I wanted to do is create a few fields that could either add a line or edit the one selected:
livecode.png
so I used this code on the card script:

Code: Select all

on addLine callType
   if callType = "add" then
   put the dgNumberOfLines of group "Capitoli" + 1 into capLines
else if callType = "edit" then
   put the dgHilitedLines of group "Capitoli" into capLines
   end if
   put field "FDCapitolo" into arrayCap[ "Capitolo" ]
   put field "FDNome" into arrayCap["Nome"]
   put field "FDRef" into arrayCap["Ref"]
   dispatch "AddData" to group "Capitoli" with arrayCap, capLines
   dispatch "ScrollLineIntoView" to group "Capitoli" with capLines
end addLine
The BTAdd and BTMod button call, onMouseUp, addLine "add" and addLine "edit" respectively.

Adding a line works properly, however dispatching "AddData" with a line that's already populated only creates a new line instead of editing the selected one. I read the API and this seems to be the correct behaviour. Can't seem to find the right command though, could you please help me a bit? I've got two questions...
1) Could you please help me in dispatching the correct command to edit a line?
2) If the AddData does not overwrite a line, why do I need to provide the command with a line number?

Thanks a million!
Cheers
Michael

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

Re: A few small questions with my first data grid attempts..

Post by Klaus » Mon Jun 02, 2014 2:14 pm

Hi Michael,

1. welcomne to the forum! :D

2. Unfortunately you choose the most complex "beast" of Liveoce objects EVER to start with: The DataGrid! 8)

3. The Datagrid library ALSO contains a handler named "addline" so maybe you should consider to rename your handler to something else to avoid possible troble!
Weaksafety wrote:1) Could you please help me in dispatching the correct command to edit a line?
Do you want to edit the line/cell INSIDE of the datagrid?
Like a doubleclick on a cell?

Or display the data in some fields (like in oyur screenshot) for editing and write the modified data back into the datagrid?
Weaksafety wrote:2) If the AddData does not overwrite a line, why do I need to provide the command with a line number?
You don't have to! :D
If you leave out that parameter, the data will be appended (after last row/index)

Load the compelte datagrid PDF manual here: http://lessons.runrev.com/m/datagrid
Although having worked with datagrids many times before, I always read the PDF acouple of times to be ready for the next project with datagrids involved! 8)


Best

Klaus

Weaksafety
Posts: 17
Joined: Mon Aug 12, 2013 5:20 pm

Re: A few small questions with my first data grid attempts..

Post by Weaksafety » Tue Jun 03, 2014 8:51 am

Thanks a lot Klaus for the welcome and the explanations!

First, I'll change the handler name to avoid trouble. Then,
Klaus wrote: Do you want to edit the line/cell INSIDE of the datagrid?
Like a doubleclick on a cell?
Or display the data in some fields (like in oyur screenshot) for editing and write the modified data back into the datagrid?
Well I'd like to start easily, so it would be something like my screenshot. The idea is: if I want to edit a line, i select it, then type the modifications in the fields, and upon pressing the button that line is overwritten.

Thanks for the heads up on the manual, I just read the API before. By reading the pdf/pages you mentioned I suppose the way to do it is to

Code: Select all

set the dgDataOfIndex[ the dgHilitedIndex of group "Capitoli" ] of group "Capitoli" to arrayCap
. I'll test it in the afternoon and report back.. :)

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

Re: A few small questions with my first data grid attempts..

Post by Klaus » Tue Jun 03, 2014 12:52 pm

Hi Michael,
Weaksafety wrote:...By reading the pdf/pages you mentioned I suppose the way to do it is to

Code: Select all

set the dgDataOfIndex[ the dgHilitedIndex of group "Capitoli" ] of group "Capitoli" to arrayCap
.
ESATTO! :D


Best

Klaus

Post Reply