Data Grid keeps creating empty last line
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 50
- Joined: Thu Apr 19, 2018 6:18 am
Data Grid keeps creating empty last line
Hi there,
I have a data grid which displays data from a text file, but it keeps creating a new empty line at the bottom. My data grid shows 14 lines at a time and so there is an auto scroll bar when more than 14 entries, there is currently 127 entries in my data grid and when I scroll down to the bottom there is a 128th empty line. How do I delete this line or stop the data grid from doing this as it's always doing this no matter how many entries?
Thanks,
Aaron
I have a data grid which displays data from a text file, but it keeps creating a new empty line at the bottom. My data grid shows 14 lines at a time and so there is an auto scroll bar when more than 14 entries, there is currently 127 entries in my data grid and when I scroll down to the bottom there is a 128th empty line. How do I delete this line or stop the data grid from doing this as it's always doing this no matter how many entries?
Thanks,
Aaron
Re: Data Grid keeps creating empty last line
Hi Aron,
sounds like there is a trailing CR in the text file?
That will cause an empty line in the datagrid.
How do you fill the datagrid? Do you set the DGTEXT to that text file
or are you creating an ARRAY first and then set the DGDATA of your datagrid?
If the first, you could :
If that does not help, please post your script.
Best
Klaus
sounds like there is a trailing CR in the text file?
That will cause an empty line in the datagrid.
How do you fill the datagrid? Do you set the DGTEXT to that text file
or are you creating an ARRAY first and then set the DGDATA of your datagrid?
If the first, you could :
Code: Select all
...
put url("file:" & "path to your text file here") into tTextFromFile
## Get rid of empty lines
filter tTextFromFile without empty
set the dgtext of grp "datagrid" to tTextFromFile
...
Best
Klaus
-
- Posts: 50
- Joined: Thu Apr 19, 2018 6:18 am
Re: Data Grid keeps creating empty last line
Hi Klaus,
I'm sorry to say that I tried that and that hasn't worked. This is my code:
Basically I have a repeat loop which takes seperate lines from the text file so that it's in the correct order that I want. All of that is working fine, the only thing is that it keeps creating a new empty entry at the bottom but I can't see a misplaced return command.
Thanks, Aaron
I'm sorry to say that I tried that and that hasn't worked. This is my code:
Code: Select all
#FILLS THE 'fContents' VARIABLE WITH DATA
put 0 into lNumber
repeat mNumber times
add 1 to lNumber
put line lNumber of url ("file:" & mFilePath) into matchNumber
add 1 to lNumber
put line lNumber of url ("file:" & mFilePath) into roundName
add 1 to lNumber
put line lNumber of url ("file:" & mFilePath) into playerOne
add 1 to lNumber
put line lNumber of url ("file:" & mFilePath) into playerTwo
add 1 to lNumber
put line lNumber of url ("file:" & mFilePath) & "-" into matchResult
add 1 to lNumber
put line lNumber of url ("file:" & mFilePath) after matchResult
if matchResult is "-" then
put empty into matchResult
end if
if fContents is empty then
put matchNumber & tab & roundName & tab & playerOne & tab & playerTwo & tab & matchResult into fContents
else
put return & matchNumber & tab & roundName & tab & playerOne & tab & playerTwo & tab & matchResult after fContents
end if
end repeat
put "matchNum" & tab & "round" & tab & "player1" & tab & "player2" & tab & "result" & return & fContents into theText
put true into firstLineContainsColumnNames
set the dgText[firstLineContainsColumnNames] of group "matchList" to theText
Thanks, Aaron
Re: Data Grid keeps creating empty last line
Hm, nothing to see in your script(s)!?
Try this one:
And please check if in -> repeat mNumber times
mNumber really holds the correct number of lines and not one more!
Sounds like the empty lines comes from this.
Try this one:
Code: Select all
...
## You are reading in the file X times, that is overkill and MUCH slower that using a variable!
## Put the content into a variable ONCE and continue with that variable!
put ("file:" & mFilePath) into tFileContent
#FILLS THE 'fContents' VARIABLE WITH DATA
put 0 into lNumber
repeat mNumber times
add 1 to lNumber
put line lNumber of tFileContent into matchNumber
add 1 to lNumber
put line lNumber of tFileContent into roundName
add 1 to lNumber
put line lNumber of tFileContent into playerOne
add 1 to lNumber
put line lNumber of tFileContent into playerTwo
add 1 to lNumber
put line lNumber of tFileContent & "-" into matchResult
add 1 to lNumber
put line lNumber of tFileContent after matchResult
if matchResult is "-" then
put empty into matchResult
end if
## No need for an IF THEN lcause here
put matchNumber & tab & roundName & tab & playerOne & tab & playerTwo & tab & matchResult & CR AFTER fContents
end repeat
## Now delete last CR of fContents
delete char -1 of fContent
put "matchNum" & tab & "round" & tab & "player1" & tab & "player2" & tab & "result" & CR & fContents into theText
##put true into firstLineContainsColumnNames
set the dgText[TRUE] of group "matchList" to theText
...
mNumber really holds the correct number of lines and not one more!
Sounds like the empty lines comes from this.
-
- Posts: 50
- Joined: Thu Apr 19, 2018 6:18 am
Re: Data Grid keeps creating empty last line
I've copied the code and no difference, it's still adding an empty line, even when I go into the property inspector there isn't an empty line in there.
-
- VIP Livecode Opensource Backer
- Posts: 9660
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Data Grid keeps creating empty last line
Is it possible that the last TWO chars of the dataSet are return?
Craig
Code: Select all
repeat until the last char of yourData <> CR
delete the last char of yourData
...
Re: Data Grid keeps creating empty last line
How do you compute -> mNumber?And please check if in -> repeat mNumber times
mNumber really holds the correct number of lines and not one more!
Sounds like the empty lines comes from this.
-
- Posts: 50
- Joined: Thu Apr 19, 2018 6:18 am
Re: Data Grid keeps creating empty last line
mNumber variable is worked out by a simple repeat loop that counts the number of lines in the text file, and then divides the total by 6 as every six lines in the file is an entry in the data grid e.g 6 lines = 1 entry, 60 lines = 10 entries. All that is working fine as well.
As for the dataSet question, what does that mean?
As for the dataSet question, what does that mean?
Re: Data Grid keeps creating empty last line
Replace dataset with fContents!
-
- Posts: 50
- Joined: Thu Apr 19, 2018 6:18 am
Re: Data Grid keeps creating empty last line
Also another thing to note is that the rogue empty bottom line doesn't hilite when you click it even though it's empty.
-
- Posts: 50
- Joined: Thu Apr 19, 2018 6:18 am
Re: Data Grid keeps creating empty last line
I've just implemented that repeat loop into my code and it's still not making a difference, could this be a bug in LiveCode?
Re: Data Grid keeps creating empty last line
No bug in LC, please post your namely repeat code!
-
- Posts: 50
- Joined: Thu Apr 19, 2018 6:18 am
Re: Data Grid keeps creating empty last line
It's ok guys, I've just created a new dataGrid and copied the specs of the first one, and this new one is working properly. Thanks for everyone's help.
Thanks,
Aaron
Thanks,
Aaron