I’m a few weeks new to Xojo and I’ve hit some strange behaviour when trying to remove a row from a listbox. As a result I’ve been experimenting as follows:
If I code:
Card_List.RemoveRow(1)
then I correctly get the second row of Card_List removed, but if I select the row to be deleted and code:
Card_List.RemoveRow(Card_List.ListItem)
then I don’t get the row removed and the debugger goes into a loop and I’ve lost control of my app
At breakpoint 1 the value of Row was 1, which is correct.
On resuming I never reached breakpoint 2 so it was hanging on line 3.
Has anyone seen this? I get the impression that there’s a bug in the RemoveRow method. It only seems to accept an integer and not an integer variable.
I’m using 2015r2.2 on a PC. Also tried this on an iMac and got the same.
What I’m saying is:
Card_List.RemoveRow(Card_List.ListIndex)
doesn’t work even when the value of ListIndex is correctly 1, but
Card_List.RemoveRow(1)
does work.
Start a new project. Add a listbox (listbox1) and a button
in the Listbox open event put
for i As Integer = 0 to 9
me.addrow "Row Number: " + str(i)
Next
in the button action event put
if Listbox1.ListIndex <> -1 Then
dim row As Integer = Listbox1.ListIndex
Listbox1.RemoveRow row
end if
Run the project, select any row in the LB and click the button
Now go figure out what is different in your original project.
[quote=194634:@Roger Clary]Start a new project. Add a listbox (listbox1) and a button
in the Listbox open event put
for i As Integer = 0 to 9
me.addrow "Row Number: " + str(i)
Next
in the button action event put
if Listbox1.ListIndex <> -1 Then
dim row As Integer = Listbox1.ListIndex
Listbox1.RemoveRow row
end if
Run the project, select any row in the LB and click the button
Now go figure out what is different in your original project.[/quote]
I don’t see how it will help me as to why, when my ListIndex is 1, it doesn’t remove row 1. I’ll just keep investigating. Maybe I’ll try 2015R1. Thanks.
Were have you placed this code? Is it anywhere within the ListBox (any Event of ListBox) ?
If you have placed it into the change event of the ListBox f.e., i would expect weird behaviour.
BTW: If you plan to later remove multiple selected Rows at once, always count down from the ListCount-1 to the first Row (= Row 0). Because the Row Numbers below the removed Rows are changing when you delete Rows.
An Example
For X As Integer = Card_List.ListCount-1 DownTo 0
If Card_List.Selected(X) Then
Card_List.Remove(X)
End If
Next X
[quote=194634:@Roger Clary]Start a new project. Add a listbox (listbox1) and a button
in the Listbox open event put
for i As Integer = 0 to 9
me.addrow "Row Number: " + str(i)
Next
in the button action event put
if Listbox1.ListIndex <> -1 Then
dim row As Integer = Listbox1.ListIndex
Listbox1.RemoveRow row
end if
Run the project, select any row in the LB and click the button
Now go figure out what is different in your original project.[/quote]
Roger,
How to add msg and action asking by Yes or No (to remove the selected row) ?
This should give you a basic Idea of how to do that Delete with Message[/quote]
Thank you Brian,
i should change some features not present in my 2015r1.
[quote=490770:@Djamel AIT AMRANE]Thank you Brian,
i should change some features not present in my 2015r1.[/quote]
This one should work with 2015 API 1 Version