Selecting multiple lines in a 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

DavJans
Posts: 275
Joined: Thu Dec 12, 2013 4:21 pm

Selecting multiple lines in a datagrid

Post by DavJans » Thu Apr 16, 2015 11:21 pm

I completely get selecting 1 line in a data grid and using the data, that part is no problem.
What I need to do is select multiple lines of a datagrid and then save all those selected lines into a text file, I cant seem to find any answers to this. someone please help.
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Selecting multiple lines in a datagrid

Post by dunbarx » Thu Apr 16, 2015 11:30 pm

Ah, DataGrids.

Try this:

Code: Select all

on mouseUp
   set the dghilitedLines of grp "yourDG" to 2,4
end mouseUp
That said, I always extract the data either with the "dgData or the "dgText", manipulate the information, and then restore as needed.

Craig Newman

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 755
Joined: Fri Jun 27, 2008 9:00 pm

Re: Selecting multiple lines in a datagrid

Post by Mikey » Fri Apr 17, 2015 2:35 pm

Craig's comment will let you use code to select multiple lines. If you are trying to let the user do it for themselves, there are two things:
1) For a desktop app, in the properties of a dg, there is a "multiple lines" checkbox. Select that, and the user can use the shift key to select additional lines.
2) On mobile, you have to code it yourself, because there is no shift key for the user to hold down while tapping on multiple lines in the dg. In that case,
  • Make your columns the full width of your datagrid b/c otherwise handling the mouseUp message will get to be tricky
  • Turn off the auto hilite of the datagrid (properties palette)
  • Write a mouseUp handler that will deal with it. That can look something like this:

    Code: Select all

    on mouseUp
       put the dgHilitedLines of me into theHilitedLinesOfMe
       put the dgindex of the target into theTarget #need to use the target and not me b/c the target receives the message and the target will be one of the columns
       #<check if the line selected is already lit.  If it is, unlight it, clean up the screen and the lists>
       repeat with i = 1 to the number of items in theHilitedLinesOfMe
          if item i of theHilitedLinesOfMe is theTarget then #in the list, already, nuke it and move on
             delete item i of theHilitedLinesOfMe
             set the dgHilitedLines of me to theHilitedLinesOfMe
             exit mouseUp # found and deleted so we're done, here.
          end if #item i of theHilitedLinesOfMe is theTarget
       end repeat # with i = 1 to the number of lines in theHilitedLinesOfMe
       #</check if the line selected is already lit.  If it is, unlight it, clean up the screen and the lists>
     end mouseUp
    

DavJans
Posts: 275
Joined: Thu Dec 12, 2013 4:21 pm

Re: Selecting multiple lines in a datagrid

Post by DavJans » Fri Apr 17, 2015 6:50 pm

1) For a desktop app, in the properties of a dg, there is a "multiple lines" checkbox. Select that, and the user can use the shift key to select additional lines.
yeah I got that far :) and it is for a desktop app.

What I can't seem to find or figure out is now that I have 3 lines selected, How do I go about sending those selected lines to a text file?
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här

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

Re: Selecting multiple lines in a datagrid

Post by sritcp » Fri Apr 17, 2015 7:33 pm

DavJans wrote:
... How do I go about sending those selected lines to a text file?
the dgHilitedIndexes --> specifies the indexes of the selected lines
getDataofIndex(pIndex) --> gets you the data array for a given index
combine --> converts an array into a list
put --> puts the list into a container, including a text file

Regards,
Sri

DavJans
Posts: 275
Joined: Thu Dec 12, 2013 4:21 pm

Re: Selecting multiple lines in a datagrid

Post by DavJans » Fri Apr 17, 2015 7:35 pm

Thank you.
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 755
Joined: Fri Jun 27, 2008 9:00 pm

Re: Selecting multiple lines in a datagrid

Post by Mikey » Sun Apr 19, 2015 9:04 pm

For those that come along, later, and find this topic, I submitted a bug report (including a FIX) for mobile.
The report number is 15240, and it also includes the fixed datagrid library, if you want to download it before the FIX is accepted and incorporated into a future version of LC.

For the record, only one of my prior FIX reports has not been built into the IDE, yet, which is more a testament to LC taking FIX reports seriously than it is my skill at adding 15 or so characters to a script to add some new feature for mobile. The DataGrid is so easy to work on and understand that all it has taken for each of my mobile FIXes is maybe one line of code each time.

DavJans
Posts: 275
Joined: Thu Dec 12, 2013 4:21 pm

Re: Selecting multiple lines in a datagrid

Post by DavJans » Thu Oct 15, 2015 6:11 pm

I have run into a problem with my script, It works great if I don't sort my data at all, but if I do sort the data I get the wrong information, here is my script, if anyone has any information that could help that would be great.

Code: Select all

on mouseUp
   put empty into fld "Field1"
   put the dgData of group "DataGrid 1" into tData1
   put the dgHilitedLines of group "DataGrid 1" into tIndexes
   
   repeat for each item tIndex in tIndexes
     put tData1[tIndex]["cert"]  & comma after fld "Field1"
     put tData1[tIndex]["job"] & comma after fld "Field1"
     put tData1[tIndex]["minorpcmkid"] & comma after fld "Field1"
     put tData1[tIndex]["heat"] & comma after fld "Field1"
     put tData1[tIndex]["creationdate"] & cr after fld "Field1"
  end repeat
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 755
Joined: Fri Jun 27, 2008 9:00 pm

Re: Selecting multiple lines in a datagrid

Post by Mikey » Thu Oct 15, 2015 7:29 pm

Do you redraw the DG after the sort?
Do you allow multiple lines to be selected?
Does the line selection happen before the sort?
By "the wrong information" do you mean that you wind up with information from the wrong line?


There is not enough info in your code sample for me to give you a suggestion.

DavJans
Posts: 275
Joined: Thu Dec 12, 2013 4:21 pm

Re: Selecting multiple lines in a datagrid

Post by DavJans » Thu Oct 15, 2015 7:36 pm

Do you redraw the DG after the sort?
Don't know?

Do you allow multiple lines to be selected?
Yes

Does the line selection happen before the sort?
I sort, then select the lines I want.

By "the wrong information" do you mean that you wind up with information from the wrong line?
Yes. I get the information that was at that line before I sorted.
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 755
Joined: Fri Jun 27, 2008 9:00 pm

Re: Selecting multiple lines in a datagrid

Post by Mikey » Thu Oct 15, 2015 10:16 pm

OK, I think I'm going to need to see more to offer more help.

DavJans
Posts: 275
Joined: Thu Dec 12, 2013 4:21 pm

Re: Selecting multiple lines in a datagrid

Post by DavJans » Thu Oct 15, 2015 10:53 pm

OK, I made a new stack.

real simple 1 datagrid 1 field 1 button. 4 columns and 5 rows of data

if you select any row and push the button you will get the same data in the field. If you sort the datagrid by any column so that it's opposite, highlight any row except the third, when you push the button you will get the wrong data in the field.
Attachments
DataGrid problem.zip
(5.3 KiB) Downloaded 264 times
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 755
Joined: Fri Jun 27, 2008 9:00 pm

Re: Selecting multiple lines in a datagrid

Post by Mikey » Thu Oct 15, 2015 11:36 pm

OK, NOW I understand.

DG's are just groups of LC objects, with a behavior script. There are two different data pieces in a DG: How it's organized internally, and how it's organized for you to view it. DataGrids don't reshuffle themselves internally when you sort them. The indexes remain the same. Use dgDataOfLine[tIndexes] to get the array of columns that are hilited. Then you can walk the columns.

DavJans
Posts: 275
Joined: Thu Dec 12, 2013 4:21 pm

Re: Selecting multiple lines in a datagrid

Post by DavJans » Thu Oct 15, 2015 11:39 pm

Thank you kind sir.
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här

DavJans
Posts: 275
Joined: Thu Dec 12, 2013 4:21 pm

Re: Selecting multiple lines in a datagrid

Post by DavJans » Fri Nov 06, 2015 4:36 pm

Working on this again, here is what I got so far.

Code: Select all

   put the dgHilitedLines of group "DataGrid 1" into theLine
   put the dgDataOfLine[theLine] of group "DataGrid 1" into tData1
     put tData1["cert"]  & comma after fld "Field1"
     put tData1["job"] & comma after fld "Field1"
     put tData1["minorpcmkid"] & comma after fld "Field1"
     put tData1["heat"] & comma after fld "Field1"
     put tData1["creationdate"] & cr after fld "Field1"
This seems to work properly for 1 line at a time, but I cant figure out how to get every line.
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här

Post Reply