Datagrid issue to add a (multiple) Line(s)

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
sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Datagrid issue to add a (multiple) Line(s)

Post by sphere » Tue Mar 08, 2016 4:35 pm

Hello,
i'm fighting with a little problem it seems, but i'm unable to solve.
a little help will be appreciated :)

when adding some data to a datagrid i get different out comes.

with this:

Code: Select all

 put the dgNumberOfLines of grp"DataGrid 1" into theLineNo
      add 1 to theLineNo
   
   put theLineNo into theDataA[theLineNo]["Nr"]
   put tFileSec into theDataA[theLineNo]["Model"]
   put fld"fouttitelnew" into theDataA[theLineNo]["Fout"]
   put fld"oplossingnew" into theDataA[theLineNo]["Oplossing"]
   set the dgData of group "DataGrid 1" to theDataA
i can add data and in the last column even multiple lines even with enter
but i can not add add a new line below or above the existing line, it updates the current line
This is what i want to use but then with more lines in the datagrid

with this:

Code: Select all

put the dgNumberOfLines of group "DataGrid 1" + 1 into theLineNo
   put theLineNo & tab & tFileSec & tab & fld"fouttitelnew" & tab & fld"oplossingnew" into theRowData
put "Nr" & cr & "Model" & cr & "Fout" & cr & "Oplossing" into theDataColumns
dispatch "AddLine" to group "DataGrid 1" with theRowData, theDataColumns, theLineNo
i can add a new line to the datagrid but i can't do the multiple line


i've added a little code to the datagrid that displays the multiple lines in a separate field when clicking on the line:

Code: Select all

on mouseUp pBtnNum
   if pBtnNum is 1 then
      put empty into fld"showsolution"
        put the dgHilitedLines of group "DataGrid 1" into theLine
        put the dgDataOfLine[theLine] of group "DataGrid 1" into theDataB
        ## theDataB is now an array variable.
        ## In the case of the Data Grid pictured above the keys of the array are id, FirstName, LastName and Title.
                
        ## This answer dialog will display: Dusty Bottoms
        #answer theDataB["Nr"] && theDataB["Model"]&& theDataB["Fout"]&& theDataB["Oplossing"]
        put theDataB["Oplossing"] into fld"showsolution"
    end if
end mouseUp
How can i correct the first script so that it does add a line to the grid. it now seems to refresh the whole grid.
thanks for any help on this.

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Location: Plymouth, UK
Contact:

Re: Datagrid issue to add a (multiple) Line(s)

Post by dave.kilroy » Tue Mar 08, 2016 7:17 pm

The approach I usually take to this is to get the current row (the one above or below which you want to add your row), then get the data from the datagrid, then create a new sub-array (or a new line if you are using the dgText) in the correct place - and lastly, reapply the data to the datagrid
"...this is not the code you are looking for..."

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm
Location: Alexandria, Virginia

Re: Datagrid issue to add a (multiple) Line(s)

Post by sritcp » Tue Mar 08, 2016 9:12 pm

Hi sphere:
sphere wrote:... i can add data and in the last column even multiple lines even with enter ...
I am sorry I could not understand this.

Code: Select all

put the dgNumberOfLines of group "DataGrid 1" + 1 into theLineNo
   put theLineNo & tab & tFileSec & tab & fld"fouttitelnew" & tab & fld"oplossingnew" into theRowData
put "Nr" & cr & "Model" & cr & "Fout" & cr & "Oplossing" into theDataColumns
dispatch "AddLine" to group "DataGrid 1" with theRowData, theDataColumns, theLineNo
If you need to add data to the end of existing data, you can skip 'theLineNo' in the AddLine command. It is needed only when you need to insert data in the middle.
sphere wrote:... I can add a new line to the datagrid but i can't do the multiple line...
Is there any reason you cannot add one line at a time and thus achieve the same result?

Here's something you can try out:
I see that you are getting the total number of lines from dgNumberOfLines and using it with the array. I don't know if that is creating some problems. Instead, try:

Code: Select all

put the keys of theDataA into theLineNo ## return-delimited list
replace return with comma in theLineNo
put max(theLineNo) into theLineNo ## making sure we get the highest key value of the array, not just the number of elements in the array.
     
   add 1 to theLineNo
   put theLineNo into theDataA[theLineNo]["Nr"]
   put tFileSec into theDataA[theLineNo]["Model"]
   put fld"fouttitelnew" into theDataA[theLineNo]["Fout"]
   put fld"oplossingnew" into theDataA[theLineNo]["Opposing"]
## now, repeat the above block as many times as you need to add multiple lines

   set the dgData of group "DataGrid 1" to theDataA
This should add multiple lines and not rewrite existing lines.
sphere wrote:..How can i correct the first script so that it does add a line to the grid. it now seems to refresh the whole grid...
When you set the dgData of a datagrid, it is going to refresh. How else is it going to include the new data?

I feel I haven't understood your difficulty or even what you want to achieve. :(

Best wishes,
Sri

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Datagrid issue to add a (multiple) Line(s)

Post by sphere » Tue Mar 08, 2016 9:15 pm

ok thanks you for your hints Dave, i will try some more to see if can can get what you suggest

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9578
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Datagrid issue to add a (multiple) Line(s)

Post by dunbarx » Tue Mar 08, 2016 9:56 pm

Hi.

I am with Dave.

I am so much more comfortable getting the dgData or the dgText, working "in LiveCode", and then restoring the whole shooting match, that I rarely work inside the, er, insides of the DG itself. There is little speed penalty, I have found, and I can get away with a great deal that would otherwise require much more detailed knowledge of the dataGrid API and properties.

Trevor DeVore likely does not do it that way.

Craig Newman

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Datagrid issue to add a (multiple) Line(s)

Post by sphere » Tue Mar 08, 2016 10:27 pm

HI,

thanks, i will test some thing tomorrow and report if it succeeds :)

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Datagrid issue to add a (multiple) Line(s)

Post by sphere » Wed Mar 16, 2016 4:27 pm

Hi Sri,

i just saw your reply, i'm sorry i missed it before.

What i ment was that on one cell of the grid i could put multiple lines.
So i have 1 line of say 4 cells, then in the last cell i can add a few lines. Somehow this works.

Yesterday i tested some things and i got some further.

I think i can use a part of your suggestions.
Thanks a lot!

So if it all works i will report back here.

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”