How to get the Index of the text line in the data grid form?

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
keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

How to get the Index of the text line in the data grid form?

Post by keram » Fri Dec 27, 2013 4:33 am

Hi,

At present I have this code to put the Index into msg box:

on mouseUp
put the dgHilitedIndexes of group "mycategories_compact" into theIndex
put theIndex
end mouseUp

but it shows the line number of the visible line on the card.

Try this in the attached stack:
Select 'Short' checkbox in the 'Select Categories' card, click on Save button and there will be 12 lines visible. When I click on 5th line that is visible (use checkbox to select it!) and click on 'Show Index of selected line' button then the message box displays 5, so it's the line number of the visible line. The Index of that line I expect to be 15.

How to change that code to display the real Index of the line instead of the line number?

I need Indexes of the selected lines, on whatever card on the stack they are selected, to show them in the 'My Selection' card and to save them in a preferences file mySelections.txt file.

Thanks for any help with this.

keram
Attachments
show index number of a line in a data grid form.zip
(26.46 KiB) Downloaded 244 times
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

LC4iOS
Posts: 88
Joined: Tue Dec 03, 2013 8:15 pm

Re: How to get the Index of the text line in the data grid f

Post by LC4iOS » Fri Dec 27, 2013 11:57 am

Not exactly sure what you're after as a result.

I use the checkbox on each row to identify which row I have selected.
That selected checkbox is always the first column.

Then I use a button to process the selected checkbox rows.

Is there an easier way to extract the DataGrid Checked Rows?
http://forums.runrev.com/viewtopic.php?f=7&t=18506
Thanks to RunRev.
Thanks to LiveCode forum members.

LiveCode v5.5.5 - iOS Android Mac Windows - 6.5 Community
27" 2012 iMac i5, MacBook Pro, MacBook Air, iPhone 5, iPhone 4
xCode 5.0.2 - iOS7 - OS X Mavericks
Paid Apple iOS Developer Program Member

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: How to get the Index of the text line in the data grid f

Post by keram » Fri Dec 27, 2013 12:29 pm

Thanks LC4iOS for your response,
LC4iOS wrote:Not exactly sure what you're after as a result.
I'd like to be able to select a text line by selecting a checkbox on any card on the attached stack and view that selection on the card 'My Selection' (the card 'myselection_compact'). So whenever a line is checkbox-selected on any card in any view, the checkbox of the same line on all other cards should be also highlighted.
That selection I want to save in a settings text file to be able to view again when the stack reopens. For this, I assume I have to get the specific Index of selected line, but not the Line number of the visible line but the Index number of the line assigned by the data grid.

I changed the attached stack little bit so that when the line is selected by checking the checkbox then the Index of the line should show up in the message box (it does not now).
LC4iOS wrote:I use the checkbox on each row to identify which row I have selected.
and it's identified by what? By its Line number or Index number?
LC4iOS wrote:That selected checkbox is always the first column.
Does it have to be the first?
I'd like to have it last. is that OK?
LC4iOS wrote:Is there an easier way to extract the DataGrid Checked Rows?
viewtopic.php?f=7&t=18506
Is that answer to my problem? Because I'm not able to apply it...

keram
Attachments
show index number of a line in a data grid form2.zip
(27 KiB) Downloaded 257 times
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

LC4iOS
Posts: 88
Joined: Tue Dec 03, 2013 8:15 pm

Re: How to get the Index of the text line in the data grid f

Post by LC4iOS » Fri Dec 27, 2013 12:56 pm

Getting super late for me here.
I probably shouldn't be answering any index type questions.

I setup my dg using the datagridhelper sample lesson.



The index in my example is really just a current line number in a page of text.

i.e. all rows I want selected have been selected via the checkbox.

Then click a button that processes the entire data grid at once.

Mine was just a simple webmail app that would move the selected rows to another email catagory.
Then refresh the original data grid without the selected rows.

----


I'm not following why you would want to tick the same row on other datagrids.
unless you're just using that as a fictitious example to get your point across.

I'm processing the data grid data as just lines separated by cr
of words separated by commas. LineDelimiter and ItemDelimiter

By puling the data out of the dg using dgText.
And searching for a value of True in the first word of each line (which is my checkbox).

-----

Yours being more preferences / options where your data is static.
You should find heaps of info on how to for preferences and options solutions.

I started with a text box containing a line for each data grid row.
Then in stack start I'd assign the text in the text box to the data grid again using dgText.
Being static - never to change.
On save I would save the dgText as just a page of text and reload on open/start.

Then later when I wanted the setting / options to change by adding lines and removing lines,
when new versions came out etc
I ended up using a SQLite database.

--

Code: Select all


on MouseUp

   set the itemDel to TAB   --datagrid columns data are delimited by a tab
   put true into pIncludeColumnNames    --use false if you don't want the column names included
   put the dgText [pIncludeColumnNames] of group "DataGrid 2" into MydgText  -- pull the data from the dg using dgText
   answer MydgText   -- display the data
   
   repeat for each line myLine in MydgText    --  Lines are delimited by cr when using dgText
      add 1 to tLineIndex                                -- this is my index / line count
      if myLine is Not empty then                    -- myLine contains the row of values
         if the first item of myLine is "true" then    -- item 1 or the first time contains a true or false depending on ticked
            put tLineIndex & "," after myTickedRowIndexes    -- save the ticked line number / index 
            put item 2 of myLIne & "  " & Item 3 of myLine & "," after myTickedRowUniqueValues  -- save my unique identifiers
         end if
      end if
   end repeat
   
   answer myTickedRowIndexes
   
   set the LineDel to Comma
   replace comma with cr in myTickedRowUniqueValues
   
   answer myTickedRowUniqueValues

...
Last edited by LC4iOS on Fri Dec 27, 2013 11:06 pm, edited 2 times in total.
Thanks to RunRev.
Thanks to LiveCode forum members.

LiveCode v5.5.5 - iOS Android Mac Windows - 6.5 Community
27" 2012 iMac i5, MacBook Pro, MacBook Air, iPhone 5, iPhone 4
xCode 5.0.2 - iOS7 - OS X Mavericks
Paid Apple iOS Developer Program Member

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: How to get the Index of the text line in the data grid f

Post by keram » Fri Dec 27, 2013 1:13 pm

Thanks again LC4iOS,
LC4iOS wrote:I'm not following why you would want to tick the same row on other datagrids.
This in order to have more flexibility to select the line from any of the other cards.
LC4iOS wrote: where your data is static.
Yes, the basic data is static consisting of a limited number of lines.
Saving preferences/options is not so difficult, I think I can manage it once I get the proper code for selecting the lines which are ticked.

I'll have a closer look at your code... but using SQLite database is probably not necessary in my case. Anyway I don't know anything about it.

keram
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

LC4iOS
Posts: 88
Joined: Tue Dec 03, 2013 8:15 pm

Re: How to get the Index of the text line in the data grid f

Post by LC4iOS » Fri Dec 27, 2013 1:35 pm

the SQLite db was for a real app with real clients with real software updates.

I'd just save the dgText as a file.
Lots of examples.

Still don't understand your need.
Unless you want to execute the same code / script / routine for all your data grids.
i.e. on a dg1 mouse up run this script - then later on a dg2 mouse up run the same script - later on dg3 mouse up same etc.




I've had a look at your dg.
I don't think its putting a proper value in the checkbox cell.

If you have dghelper
http://lessons.runrev.com/s/lessons/m/4 ... rid+Helper
Find the lesson for checkbox.

without dgh
http://lessons.runrev.com/s/lessons/m/d ... -data-grid
There is a sample .lc app to download at the top.



There must be a reason I'm using dgText as its simpler (for me) than trying to use:

-- dgHilitedIndexes
--dgHilitedIndex
--- get the dgHilitedIndexes
--- set the dgHilitedIndexes of group "DataGrid" to pIndex
--- Returns a comma delimited list of the indexes that are currently selected.

--dgHilitedLines
--dgHilitedLine
--- get the dgHilitedLines
--- set the dgHilitedLines of group "DataGrid" to pLine
--- Returns a comma delimited list of the line numbers that are currently selected.


-- Get the dgHilitedIndexes of group "DataGrid 2"
-- answer it
--      put the dgHilitedIndexes[the dgHilitedLines of group "DataGrid 2" ] of group "DataGrid 2" into tIndex
-- answer tIndex




hth
Thanks to RunRev.
Thanks to LiveCode forum members.

LiveCode v5.5.5 - iOS Android Mac Windows - 6.5 Community
27" 2012 iMac i5, MacBook Pro, MacBook Air, iPhone 5, iPhone 4
xCode 5.0.2 - iOS7 - OS X Mavericks
Paid Apple iOS Developer Program Member

LC4iOS
Posts: 88
Joined: Tue Dec 03, 2013 8:15 pm

Re: How to get the Index of the text line in the data grid f

Post by LC4iOS » Mon Jan 06, 2014 10:11 pm

And saving and recovering tab delimited data:

http://lessons.runrev.com/s/lessons/m/d ... mited-data
Thanks to RunRev.
Thanks to LiveCode forum members.

LiveCode v5.5.5 - iOS Android Mac Windows - 6.5 Community
27" 2012 iMac i5, MacBook Pro, MacBook Air, iPhone 5, iPhone 4
xCode 5.0.2 - iOS7 - OS X Mavericks
Paid Apple iOS Developer Program Member

Post Reply