Problems with selecting lines in 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

Post Reply
M.M
Posts: 4
Joined: Tue Aug 28, 2018 12:53 pm

Problems with selecting lines in DataGrid

Post by M.M » Tue Aug 28, 2018 1:11 pm

Hi all,
I have a simple question regarding the selection of some lines in my DataGrid.

Here is an example of my DataGrid:

Company Company_Code
DHL 10
UPS 20
Express 27

Now I have a text string with "10,27"

Is it possible to identify the company_code(s) in my DataGrid with the text string and select the complete line?

Thank you, Moritz

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

Re: Problems with selecting lines in DataGrid

Post by dunbarx » Tue Aug 28, 2018 2:16 pm

Hi.

I always extract the full suite of DG information with "DGText", process in the "clear", and then restore.

The tools available in LC proper are far more accessible and powerful than any native DG functionality. The extra two steps of extracting and restoring are trivial.

Once you have the line(s) of interest while processing back in LC, you simply select them in the DG after restoring.

Craig Newman

EDIT.

Are you OK with that "processing in the clear"? In other words, dataGrids notwithstanding, can you do what you need to with finding the lines of interest?

M.M
Posts: 4
Joined: Tue Aug 28, 2018 12:53 pm

Re: Problems with selecting lines in DataGrid

Post by M.M » Wed Aug 29, 2018 2:06 pm

Hi.

I already started to put the Data Grid into a clear but I have still problems with it:

Code: Select all

 ## Put the Data Grid into DG_List
   put the dgText of group "dg_zahlungsart_ausblenden" into DG_list
   
   ## Delemiter
   set the itemdelimiter to tab
   
   ## start checking if content from string zahlungsart_auslassen3 exist in Data Grid
   repeat for each item tItem4 in zahlungsarten_auslassen3
      repeat for each line tLine1 in DG_list
         
         ## put the items into variables
         put item 2 of tLine1 into Vergleich_WI
         put tItem4 into Vergleich_ZA
         
         
         ## compare the variables
         if Vergleich_WI = Vergleich_ZA
         then
            ## hilite the selected lines (does not work)
            put the dghilitedlines of group "dg_zahlungsart_ausblenden" into zeile
            
            answer zeile
            
         else 
            
         end if
         
      end repeat
   end repeat
any idea what is going on wrong?

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Problems with selecting lines in DataGrid

Post by Klaus » Wed Aug 29, 2018 2:37 pm

Hallo Moritz,
M.M wrote:
Wed Aug 29, 2018 2:06 pm
any idea what is going on wrong?
leider eine ganze Menge...

so sollte es klappen:

Code: Select all

...
   ## Put the Data Grid into DG_List
   put the dgText of group "dg_zahlungsart_ausblenden" into DG_list
   
   ## Delemiter
   set the itemdelimiter to tab
   
   ## zahlungsarten_auslassen3 is defined as GLOBAL or LOCAL variable?
   ## so the content of zahlungsarten_auslassen3 = TAB delimited list of numbers, right?
   
   ## We will work here with ITEMOFFSET, so we need to:
   set the wholematches to TRUE
   ## Simply beacause 1 is also in 11, but we want a "whole match" :-)
   
   ## We use "repeat for each", so we need to manage our own COUNTER
   put 0 into tCounter
   
   ## We collect the numbers of the lines that need to be be hilited:
   put empty into tLinesToBeHilited
   
   # repeat for each item tItem4 in zahlungsarten_auslassen3
   repeat for each line tLine1 in DG_list
      add 1 to tCounter
      
      if itemoffset(item 2 of tLine,zahlungsarten_auslassen3) <> 0 then
         ## we need to collect all the lines adn then HILITE them all together afterwards
         put tCounter & "," after tLinesToBeHilited
      end if
   end repeat
   
   ## Delete trailing COMMA in tLinesToBeHilited
   delete char -1 of tLinesToBeHilited
   
   ## NOW we hilite all found lines "en bloc"
   if tLinesToBeHilited <> EMPTY then
      set the dgHilitedLines of grp "dg_zahlungsart_ausblenden" to tLinesToBeHilited
   end if
...
Please read my comments in the script.

Datagrids are the most complex beasts in LC, but also the most attractive controls,
which is very dangerous for newbies. :D

BTW, we also have a german LC forum:
http://www.livecode-blog.de/forums/foru ... ode-forum/

Gruß/Best

Klaus

M.M
Posts: 4
Joined: Tue Aug 28, 2018 12:53 pm

Re: Problems with selecting lines in DataGrid

Post by M.M » Wed Sep 12, 2018 8:14 am

Hallo Klaus,

Vielen dank für deine schnelle Antwort. Es funktioniert genau wie es soll. Habe mich auch gleich mal in dem Deutschen Live Code Forum angemeldet.

Wünsche noch einen schönen Tag.

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Problems with selecting lines in DataGrid

Post by Klaus » Wed Sep 12, 2018 8:26 am

Great you got it working!

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”