DataGrid - Problems

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
Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

DataGrid - Problems

Post by Simon Knight » Mon Dec 28, 2009 2:56 pm

Hi,
I am investigating Datagrids and am having problems with the basics. The code below is run when a button is pressed. The only other control on the stack/card is the datagrid (called DataGrid 1). When run the answer dialog and the beep occur but the datagrid remains blank - any ideas where I am going wrong?

Simon

Code: Select all

on mouseUp
   ## Create tab delimited data. 
   ## Note that first line has name of columns. 
   ## Providing names tells Data Grid how to map 
   ## data to appropriate columns. 
   put "state" & tab & "code" & cr & "ALABAMA" & tab & "AL" & cr & "ALASKA" & tab & "AK" into theText
   answer theText
## Let Data Grid know that first line has column names
put true into firstLineContainsColumnNames
set the dgText [ firstLineContainsColumnNames ] of group "DataGrid 1" to theText
beep
end mouseUp
best wishes
Skids

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Contact:

Re: DataGrid - Problems

Post by trevordevore » Mon Dec 28, 2009 4:02 pm

Just saw this post. Not sure how it slipped through before. You probably already found the solution but I will answer in case someone comes across this later on.

The most likely problem is that you do not have columns named "state" and "code" in your Data Grid. If the columns don't exist in the Data Grid then the data will not be displayed.
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Re: DataGrid - Problems

Post by Simon Knight » Tue Dec 29, 2009 12:37 am

Trevor,

Thanks for the help - yes you are quite correct in that I failed to name the columns before running the code and no I had not discovered it for my self.

Interestingly the same failure to name the columns causes a very odd effect on a more complex set of stacks and data where once the button is pressed it is no longer possible to select the Datagrid while in edit mode, well it is possible to select it but it automatically deselects its self all very confusing.

Thanks also for all the information on your web site and the GLX plugin which I have just started experimenting with.
best wishes
Skids

Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Re: DataGrid - Problems

Post by Simon Knight » Tue Dec 29, 2009 10:00 am

I have just read the following:

"pText is assumed to be a collection of data where each row is delimited by the return character and
each item is delimited by a tab. You can map each item of each line in pText to a particular key in an
array (and thus a table column) by passing in true for pFirstLineContainsHeaders. If true then the data grid will extract the first line of pText and use the values for the internal key/column names. The default value for pFirstLineContainsHeaders is false."

This was how I expected the code snippet to operate i.e. I send a TSV/CSV file to a datagrid with the "FirstLineContainsHeaders" set to true and it defines the columns based on the first row of data passed.

Have I misunderstood the text or is the failure a bug?
best wishes
Skids

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Contact:

Re: DataGrid - Problems

Post by trevordevore » Tue Dec 29, 2009 5:09 pm

It isn't a bug. If you keep reading you will see the sentence:
Note that if pFirstLineContainsHeaders is true then the columns must already exist in your data grid table in order to be displayed.
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Contact:

Re: DataGrid - Problems

Post by trevordevore » Tue Dec 29, 2009 5:11 pm

Interestingly the same failure to name the columns causes a very odd effect on a more complex set of stacks and data where once the button is pressed it is no longer possible to select the Datagrid while in edit mode, well it is possible to select it but it automatically deselects its self all very confusing.
I'm not sure what would cause this exactly but I wonder if an error occurred when assigning data to the Data Grid and the IDE failed to report the error. The error then caused some "confusion". If you can replicate the steps to reproduce the problem let me know and I will see if I can track it down.
Thanks also for all the information on your web site and the GLX plugin which I have just started experimenting with.
You're welcome.
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

Post Reply