Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox ReadOnly ? 1

Status
Not open for further replies.

foxup

Programmer
Dec 14, 2010
328
CA
Hi All,

I have a question. I have a Listbox which contains data from an array (basically lists all the items in the array and gives the end-user a chance to scroll thru all the items). I want the Listbox to be "READONLY" but NOT disabled. You know what I mean? The user should be able to just 'scroll" up & down the listbox (with the click disabled) basically. Am I missing something or is there no "READONLY" type for a listbox?


Any help please.


Thanks,
FOXUP!
 
As you have discovered, there's no ReadOnly property for a listbox.

The only workaround that immediately comes to mind is to store the current ListIndex when the control gets focus, and to restore it when it loses focus. The user will still be able to make a selection, but the selection will be cancelled when they leave the control.

Not very elegant, I admit. Maybe someone else can suggest something better.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Hi Mike,

Is there anyway of disabling all items in the listbox? I've read the backslash '/' does it but I can't get it to work.
I've tried this:
this.RowSource = '\]'+gaDatabase in the init of the listbox but to no avail.

I've tried this in the :
'\]'+gaDatabase

in the rowsource property but,again, doe snot work.

Anyy other suggestions?


Thanks,
FOXUP!
 
Foxup, it's not the RowSource where you put the backslash. It's the actual values. So, given that you are populating it from an array, you would have to loop through the array, adding a backslash to the front of each item.

Hope that makes sense.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Sorry, how do I do that so that the items are all showed as disabled?
 
Why don't you change your Form display object to a Grid where you do have a ReadOnly property?

Good Luck,
JRB-Bldr
 
Because every part of the program is "built around" the listbox data. There has to be a simple way to do this?
 
Sorry, how do I do that so that the items are all showed as disabled?

Something like this:

Code:
FOR lnI = 1 TO ALEN(aListBoxArray)
  aListBoxArray(lnI) = "\" + aListBoxArray(lnI)
ENDFOR

This assumes aListBoxArray is the array that populates the listbox. Do this in the Init of the listbox.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
I get operator/operand type mismatch??
 
What data types are the array contents? I was assuming they are character strings. If not, you will have to convert them, e.g. by using TRANSFORM().

Also, I was assuming that the array was one-dimensional. If it's not, you should only loop through the first column (add ,1 to the subscript in each case).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
I get operator/operand type mismatch

Well that's pretty self-exlanatory isn't it?

It means that your array contains numerics which cannot be combined with the character '\'

Code:
aListBoxArray(lnI) = "\" + ALLTRIM(STR(aListBoxArray(lnI)))

So unless you change all of your array contents to character representations of the numerics, you aren't going to get this approach to work.

Good Luck,
JRB-Bldr



 
Mike is correct in that if you have a multi-dimensional array, your array column contents beyond the one column you want to display could be something other than a character - thereby causing the problem.

Good Luck,
JRB-Bldr
 
To summarise, do this:

Code:
FOR lnI = 1 TO ALEN(aListBoxArray, 1)
  aListBoxArray(lnI, 1) = "\" + TRANSFORM(aListBoxArray(lnI))
ENDFOR

That will work with any data type in the array, and any number of columns.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Well there then !!

LOL


Mike, awesome (as usual) !! :)

Super. Many thanks. Star!

FOXUP!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top