Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Wed Jun 20, 2018 11:47 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Problem with listbox.RemoveRow (SOLVED)
PostPosted: Wed Dec 26, 2012 5:05 pm 
Offline

Joined: Sat Feb 04, 2012 1:26 pm
Posts: 86
Location: Italy
Hi,
I am practicing with the listbox.
I have two different listboxes and I wish to:
double click one of the many raws inside listbox 1,
add that row to listbox 2,
remove that row from listbox 1
and so on.

this is the code I wrote:
Listbox1.cell(listbox1.listcount,-1) = listbox2.cell(Listbox2.ListIndex,-1)
Listbox2.RemoveRow(listbox2.ListIndex)


Problem arise when i doubleclick on the same row, faster, let's say 1 times a second, giving me an outofboundesexception error on the listbox2.RemoveRow(listbox2.ListIndex). If I click even faster, but on different rows, the problem doesn't arise.
any suggestions?
thanks for any help.
Antonio


Last edited by Antonio on Sat Jan 26, 2013 9:17 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Problem with listbox.RemoveRow
PostPosted: Wed Dec 26, 2012 9:13 pm 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
first off you code is backwards from your description


in the CELLCLICK event of LISTBOX1
if row<me.listcount then
me.listindex=row // makes sure listindex and row are in synch (since doubleclick can't see "row"
end if


in the DOUBLECLICK event of LISTBOX1
dim i as integer
dim x as integer
if me.listindex<0 then exit sub ' no row selected
listbox2.addrow
x=listbox2.lastindex
for i=0 to me.columncount-1
listbox2.cell(x,i)=me.cell(me.listindex,i)
next i
me.removerow me.listindex
me.invalidatecell(-1,-1)
listbox2.invalidatecell(x,-1)

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem with listbox.RemoveRow
PostPosted: Thu Dec 27, 2012 2:18 pm 
Offline

Joined: Sat Feb 04, 2012 1:26 pm
Posts: 86
Location: Italy
Hi Dave,
thanks for helping.

After reading your direction, I examined my code to understand the errors I made.
As for the CellClick event:
First of all, I think I misunderstood the listindex property. i Thought it was the same as the row argument in CellClick function.
Then, does your Listbox1 CELLCLICK event code must be put there because CellClick function contain "row" as agument and row stores the numbert of the clicked cell?

As for DoubleClick event:
Just to understand, I saw you used the for next cycle to copy all the columns from listobox1 to listbox2. Is the code I wrote
Listbox1.cell(listbox1.listcount,-1) = listbox2.cell(Listbox2.ListIndex,-1)

some way wrong? it seems to work correctly.


Still do not understand why if i doubleclick the listbox rows slowly, my code works, if i doubleclick faster, not. It might depend on the speed the OS updates the listindex value?


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem with listbox.RemoveRow
PostPosted: Thu Dec 27, 2012 2:28 pm 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
I think the last two lines of my example is the key.


You are able to click the cell before the system "decides" to refresh the listbox... my example says "do it NOW"

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem with listbox.RemoveRow
PostPosted: Thu Dec 27, 2012 3:10 pm 
Offline

Joined: Sat Feb 04, 2012 1:26 pm
Posts: 86
Location: Italy
Dave,

I am not sure I have fully understood. Did you mean this code as the one which refresh the listbox?:

me.invalidatecell(-1,-1)
listbox2.invalidatecell(x,-1)



I have modified my original erroneus code, just by adding the code for the listbox1 CellClick event:

if row<me.listcount then
me.listindex=row // makes sure listindex and row are in synch (since doubleclick can't see "row"
end if


as for the Doubleclick event, I kept:

Listbox1.cell(listbox1.listcount,-1)=  listbox2.cell(Listbox2.ListIndex,-1)
Listbox2.RemoveRow(listbox2.ListIndex)


seems it works.


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem with listbox.RemoveRow
PostPosted: Thu Dec 27, 2012 3:18 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
In your DoubleClick code, test for a valid ListIndex. The rest of Dave's code is not necessary. As I understand it, the problem you had was when you quickly double click the last row, the DoubleClick event is triggered twice. The first time, it removes the row. That sets ListIndex to -1, because there is no longer any highlighted row. The second time, ListIndex is invalid, so your code errors out. Simply change your DoubleClick code to
if listbox2.ListIndex >= 0 then
Listbox1.cell(listbox1.listcount,-1) = listbox2.cell(Listbox2.ListIndex,-1)
Listbox2.RemoveRow(listbox2.ListIndex)
end if


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem with listbox.RemoveRow
PostPosted: Thu Dec 27, 2012 4:13 pm 
Offline

Joined: Sat Feb 04, 2012 1:26 pm
Posts: 86
Location: Italy
Tim,
the issue was a little bit different, I'll try to explain better: suppose we have two listboxes, LB1 and LB2.
LB1 contains, let's say, 20 rows. LB2 contains no rows, yet.
Now I wish to click on one of the 20 rows on the LB1 to transfer it to LB2 listbox. (row must appear on LB2 and must disappear from LB1). If I position the mouse pointer on one of the raw (for semplicity let's say on row 10) and I begin to doubleclick slowly (one double click each second), the row is transferred from LB1 to LB2 (so, now we have 19 row on LB1 and 1 on LB2). I keep the mouse pointer in the same position and double click again. and again until all the remaining rows from LB1 are gone to LB2. If i double click slowly (more than 1 second, circa) it works, but as soos as i begin to doubleclick faster I get the outofboundexception. Consider, anyway, that keeping the mouse on the same position, while at the first dobuleclick i have under the mouse pointer row number 10, at the following double click i have, under the mouse pointer row number 11 as the number 10 went on LB2 and disappeared from LB1, letting the following rows rise,

As for the code you showed me, it doesn't work well. whle Daves' works correctly.

The problem I have with your code is that if i dblclick slowly it work, it i begin to dblclick faster, the raw stop from being copied to LB2 and on LB1 row not even appear selected.


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem with listbox.RemoveRow
PostPosted: Thu Dec 27, 2012 4:28 pm 
Offline

Joined: Sat Feb 04, 2012 1:26 pm
Posts: 86
Location: Italy
Tim, if you wish you might replicate my code to see better the problem,


Create 2 listboxex on a window.

In the listbox1 open event put:

dim rowcount as integer
for rowcount = 1 to 10
me.AddRow "aaaaa"
next rowcount




in the listbox1 doubleclick event put:

if listbox1.ListIndex >= 0 then
Listbox2.cell(listbox2.listcount,-1) = listbox1.cell(Listbox1.ListIndex,-1)
Listbox1.RemoveRow(listbox1.ListIndex)
end if



Now click fast on the listbox1 rows.


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem with listbox.RemoveRow
PostPosted: Thu Dec 27, 2012 4:44 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
Works fine here. Not sure what the problem is then.


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem with listbox.RemoveRow
PostPosted: Thu Dec 27, 2012 4:47 pm 
Offline
Real Software Engineer

Joined: Sat Dec 24, 2005 8:18 pm
Posts: 7858
Location: Canada, Alberta, Near Red Deer
two listboxes
clicking like mad
no out of bounds exception occurs

one of the issues is definitely that if you just click like crazy then they don't all get recognized as "double clicks"

_________________
Norman Palardy (Real Software)


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem with listbox.RemoveRow
PostPosted: Thu Dec 27, 2012 5:26 pm 
Offline

Joined: Sat Feb 04, 2012 1:26 pm
Posts: 86
Location: Italy
Still having problem here.
Besides the Win version I also compiled as Osx and behave the same manner.
What I do is the following:
I click slowly (one doubleclick every each second) on the first row of listbox1, and the rows are transferred to listbox2. (keep clicking, always, on the first row, until listbox1 is empty)
I click faster (one doubleclick every less than a second, always on the first row) and the rows are not transferred. :shock:


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem with listbox.RemoveRow (SOLVED)
PostPosted: Sat Jan 26, 2013 9:16 am 
Offline

Joined: Sat Feb 04, 2012 1:26 pm
Posts: 86
Location: Italy
Hi,
I think the problem is now solved. It was not an issue affecting the code, but the properties.
I realize, the problem arose when the listbox "enableDrag" property was unchecked.
When the "enableDrag" is checked it works as expected.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group