Get row of data from datagrid bases on the name in Col 1.

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
CAsba
Posts: 384
Joined: Fri Sep 30, 2022 12:11 pm

Get row of data from datagrid bases on the name in Col 1.

Post by CAsba » Thu Feb 23, 2023 2:04 pm

Hi, I've set up a simple name and address, etc., datagrid table. The user enters name, etc details by a series of ask dialogs, and a customer code is generated - 3 or 4 characters, then the whole is entered into the datagrid. The customer code is in col 1 of the table.
When the user wants to raise a document for a customer (invoice/delivery note, etc) he selects the customer code from a combo menu that puts the cust. code into a field. The system should then use the field to get the cust. data to put into address fields on the document.
I've tried interpreting suggestions from previous forum submissions, and looked up the lessons, but without success.
Can anyone give me a simple piece of code to do the trick ?

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

Re: Get row of data from datagrid bases on the name in Col 1.

Post by Klaus » Thu Feb 23, 2023 2:45 pm

Hi CAsba,

I presume the customer code is a unique number, right?
Then you could use LINEOFSSET or FILTER.
Lineoffset:

Code: Select all

...
put fld "the one with the code" & TAB into tCode
put the dgtext of grp "all addresses etc..." into tText
put lineoffset(tCode,tText) into tline
if tLine = 0 then
  beep
  answer "No such code!"
  exit to top
end if
put line tLine of tText into tFoundLine
set itemdel to TAB
## Now you have the line and can extract all wanted columns from tFoundLine
...
FILTER:

Code: Select all

...
## Same as above but we also add a WILDCARD -> *
put fld "the one with the code" & TAB & "*" into tCode
put the dgtext of grp "all addresses etc..." into tText
filter tText with tCode
if tText = EMPTY then
  beep
  answer "No such code!"
  exit to top
end if
set itemdel to TAB
## Now you have the line and can extract all wanted columns from tText, 
## which will now only contain the one line in question
...
Best

Klaus

CAsba
Posts: 384
Joined: Fri Sep 30, 2022 12:11 pm

Re: Get row of data from datagrid bases on the name in Col 1.

Post by CAsba » Thu Feb 23, 2023 4:00 pm

Hi Klaus, Once again, many thanks - it worked perfectly...

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”