Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently December 22nd, 2024, 9:37 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Removing items from ListBox
PostPosted: October 18th, 2010, 3:26 am 
Offline

Joined: July 12th, 2009, 10:33 am
Posts: 124
Hi

I'm having real problems getting seemingly simple listbox operations working. The listbox is populated by the user at runtime, but I then need to allow them to remove items from the list. I've tried SetSelection/ReplaceSelection(""), SetListBoxSelection/ReplaceSelection(""), storing the list in a variable with "\n" separators then searching for \n etc. The attached gives an idea about the routes I have tried, but none of them seem to produce any desirable result.

Anyone able to help point to a solution? I've searched here and can't see why the easiest method doesn't work.

Many thanks in anticipation
Dan
(Using V7.04)


You do not have the required permissions to view the files attached to this post.

_________________
V9.6. Windows 10. Testing on PC, Mac, iPad.


Top
 Profile Visit website  
 
 Post subject: Re: Removing items from ListBox
PostPosted: October 18th, 2010, 3:00 pm 
Offline
Godlike
Godlike

Joined: November 12th, 2005, 1:56 am
Posts: 1474
Location: SFBay Area
Opus: OpusPro v9.0x, & Evol.
OS: Vista32
System: Core 2 duo 2Ghz, RAM 3GB, Nvidia Go 7700 - laptop
Dan,

I've looked at your test.imp. I give you credit for trying all of the available approaches. :wink:
(you've got a syntax issue there with an unnecessary '+' sign after the '=' operator)
(the rest is a mixed metaphor)

Let's focus and solve one thing at a time (of the two stated objectives: delete items from LB, and replacing text in a line).
As always there are several ways to accomplish something, so others may suggest better or more direct methods.

Deleting items from Listbox (at runtime).
First, I would set Listbox properties to have a variable, eg. LB01_selected, to 'store selected text'.
Next, I'll just outline one approach you can try:
1. create a FOR LOOP to run through ALL of the lines of the ListBox (see later comments below)
2. you have a variable, 'selectedindex', for the User's choice
3. set a var revisedcontents = "";
4. make an IF statement if ( i != selectedindex)
5. then do something like this:
ListBox.SetListBoxSelection(i)
revisedcontents += LB01_selected ;
6. wait(0) //you may be able to eliminate this and see if it works without it
7. close the LOOP
8. ListBox.SetSelection(0, -1) ;
ListBox.ReplaceSelection( revisedcontents );

For the other part of the problem, here are some hints... you can explore how the following commands work together. Or, you may choose to use some other approach.
Code:
var charInfo = ListBox.LineIndex(1)
Debug.trace( "Line starts at \t" +charInfo +"\n")

var numOfChars = ListBox.LineLength(1)
Debug.trace( "Line length is \t" +numOfChars +"\n")

var numOfLines = CountLines(ListBox)    //this same command can be used to count lines in a variable instead of an object
Debug.trace( "Object has \t" +numOfChars +"\t line(s)\n")
//the number of lines value can be useful for running through a FOR LOOP  --- usually stop loop at    i < numOfLines;   //depending what you are doing


//for Your Replace Line 2
var UserNewInput = "Here is my new content" ;  //you will adapt this to however you plan to get changes from User
ListBox.SetSelection(charInfo, charInfo +numOfChars -1) ;
ListBox.ReplaceSelection( UserNewInput );



//for Your Get 2
ListBox.SetListBoxSelection(1)
var ListBoxLine2 =  LB01_selected ;  //this assumes you have associated this variable, LB01_selected, to the ListBox in its Properties dialogue.

[Lar EDIT:] I have changed the index value in the 4th line above to 1 (it was 0, because I was testing those separately -- but we really want to operate on the same line)

Dan, I chose to give this to you in pieces and in outline so you can think through what is going on... and once you get a feel for it I think you'll be able to reuse these methods and extend them later.

_________________
_good things come to those who wait(0)_


Last edited by Lar_123 on October 20th, 2010, 12:00 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Removing items from ListBox
PostPosted: October 18th, 2010, 3:08 pm 
Offline
Godlike
Godlike

Joined: November 12th, 2005, 1:56 am
Posts: 1474
Location: SFBay Area
Opus: OpusPro v9.0x, & Evol.
OS: Vista32
System: Core 2 duo 2Ghz, RAM 3GB, Nvidia Go 7700 - laptop
One last thing I forgot to mention regarding: ListBox.SetListBoxSelection(1)
That command only activates a 'selection' as a pointer. I do not think it returns any value for you. But if you created the 'associated' variable for a Listbox's selected item, that is a value you can use.

_________________
_good things come to those who wait(0)_


Top
 Profile  
 
 Post subject: Re: Removing items from ListBox
PostPosted: October 18th, 2010, 11:28 pm 
Offline

Joined: July 12th, 2009, 10:33 am
Posts: 124
Thanks Lar - I really appreciate the time you have taken there. That was one method I hadn't tried.

The only thing I had to do was store the SelectedIndex first as the original one changed during the 'For' loop. I'm also storing the number of lines in each listbox for another purpose, so used this (others would need the 'Count' first).

Attached file, should anyone need this. The bottom solution is the one that works.

Cheers again
Dan



var RevisedContents = "";
var UserSelectedIndex = SelectedIndex

for (i=0;i<NoLines;i++)
{

if (i != UserSelectedIndex)
{
ListBox3.SetListBoxSelection(i)
RevisedContents += ListText + "\n";
}

}
ListBox3.SetSelection(0, -1) ;
ListBox3.ReplaceSelection(RevisedContents );


You do not have the required permissions to view the files attached to this post.

_________________
V9.6. Windows 10. Testing on PC, Mac, iPad.


Top
 Profile Visit website  
 
 Post subject: Re: Removing items from ListBox
PostPosted: October 19th, 2010, 3:13 am 
Offline
Godlike
Godlike

Joined: November 12th, 2005, 1:56 am
Posts: 1474
Location: SFBay Area
Opus: OpusPro v9.0x, & Evol.
OS: Vista32
System: Core 2 duo 2Ghz, RAM 3GB, Nvidia Go 7700 - laptop
D,
Good, you got it. And you remembered to add the +"\n" which I forgot.
(for those who might 'pick-up' on this solution, the variable 'ListText' that Dan uses is probably associated to the listbox items (in Properties) )

As a side-note, I have found some convenient uses for Listbox objects as a way a manipulating SETS of things... and that Listbox does not even have to be visible -- it can be positioned off-page. One example/use is as a way to construct a lookup table. And these match-up very well with Arrays, where you can use the same index from the User's Listbox selection, so not need extra Listbox.

_________________
_good things come to those who wait(0)_


Top
 Profile  
 
 Post subject: Re: Removing items from ListBox
PostPosted: October 19th, 2010, 10:03 am 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Lar_123 wrote:
And these match-up very well with Arrays, where you can use the same index from the User's Listbox selection, so not need extra Listbox.[/color]


Yes, that's the way I use them. I've added a scribble and an IMP to our website.

http://www.live.interaktiv.co.uk/index. ... Itemid=166

Mack

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject: Re: Removing items from ListBox
PostPosted: November 8th, 2010, 8:06 am 
Offline

Joined: July 12th, 2009, 10:33 am
Posts: 124
Hi

I've run into another listbox hitch. I think I must be going mad because I had this working previously in my pub (and the discussion above indicates that this wasn't an issue at the time). However, I've recreated the problem in the attached test file, so am wondering what has happened.

The trouble is that I can't select a list item using the mouse in a clone of a listbox. If I use the button to create a clone in the attached pub, I can only select the list items with the keyboard, not the mouse. The mouse continues to work in the original.

Could someone please check that this problem is an also an issue for you and not just me. I am stumped by the fact that this worked previously.

Many thanks
Dan


You do not have the required permissions to view the files attached to this post.

_________________
V9.6. Windows 10. Testing on PC, Mac, iPad.


Top
 Profile Visit website  
 
 Post subject: Re: Removing items from ListBox
PostPosted: November 8th, 2010, 11:38 am 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
It'll only work if the List boxes are level with each other. As far as I'm aware, you'd need to build custom list boxes if you want to clone them.

Mack

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject: Re: Removing items from ListBox
PostPosted: November 8th, 2010, 1:41 pm 
Offline

Joined: July 12th, 2009, 10:33 am
Posts: 124
Thanks Mack

As usual, you are spot on. I moved the original in my sample vertically downwards a few pixels and bingo. I must have lucked out with the level originally, hence it appearing to work. I'm glad I found this out now.

I'll have a look at a custom list box tomorrow. I presume I need to start with a simple text box and work from there.

Cheers
Dan

_________________
V9.6. Windows 10. Testing on PC, Mac, iPad.


Top
 Profile Visit website  
 
 Post subject: Re: Removing items from ListBox
PostPosted: November 8th, 2010, 1:48 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Hi Dan,

Our custom one is a frame with Text Boxes.

Mack

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 50 guests


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
You cannot post attachments in this forum

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