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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display logical field and character field in listbox 1

Status
Not open for further replies.

benman

Programmer
May 3, 2006
35
HK
Dear All :

Is it possible to display 2 fields inside lisbox: 1st column being logical field displaying in checkbox, 2nd column being character field display as usual character.

Below list Listbox.Init for your correction.

Many thanks and happy programming.
Smarty

Code:
SELECT Button6
zap
GO TOP
IF EOF() AND BOF()	&& empty table
	FOR I = 1 TO 6
		APPEND BLANK
		replace Button6.serial WITH ALLTRIM(STR(I))
		replace Button6.lcheck WITH .T.
	ENDFOR
ENDIF

this.RowSourceType = 6	&& Fields
this.RowSource = "Button6.lcheck, serial"
this.ColumnCount = 2
 
Benman,
If I'm reading into what you are trying to do is show a check mark character next to an item... why not just append the check character to the text item in the list box at the time it is checked / unchecked? Then you don't need two columns.

This.Value = This.Value + " ?"

Or, if you want the check to preceed:

This.Value - "? " + This.Value

Where it assumes your value is a character value. If it is not, you'll want to convert it to character first.



Best Regards,
Scott

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Dear Scott :

thanks for kind response.

I want to let me check and uncheck the logical field inside the listbox. Character field is for display and shall have no amendment.

Happy assistance in advance.
Smarty
 
Benman,
Sorry, I really should have answered your question... the answer is no, you can not mix those two types of controls in a standard FoxPro List box. You could make up your own "ListBox" control, using containers, and code and stuff like that, and it is possible, but would take a lot of work, beyond the scope of a Tek-Tips answer... maybe a FAQ if someone wanted to build one.
To that, I'd suggest you have 2 options:
1) As I mentioned above, and you can also update the logical fields in your table at the same time, and then use them to re-build your list box options when you reload the control on the screen, by placing the check box character in the display value, using an array to contain your list box options.
2) Use a grid. It has scroll bar control, so if you have more than just one or 2 things you can still navigate easily to them. A grid easily accomodates multiple control types in the grid.
3) Build a custom control of your own. This is tricky, but fun and rewarding, and can get you a nomination for extreme cleverness by your users.



Best Regards,
Scott

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Hi Smarty,

I have seen this done by using the Listbox's Picture property. Set this to one of two images: one representing a checkbox with a tick, and one without. Then, dynamically change the image according to the state of the underlying logical field.

There is an example of this technique in Kilofox ("1001 Things ... "), page 151. However, I have never been able to get it working to my satisfaction (my fault, not Andy or Marcia's).

A better approach might be to use a grid. There's no problem in putting checkboxes in grids.

Or, use a Listview. These support checkboxes very well. If you find the standard Listview difficult to work with, try my freeware Simplelist class ( which is a wrapper for Listview. You can make it do checkboxes with just a couple of lines of code.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Dear Scott :

I took you advice No.2 and that is ok.

Many thanks.
Smarty

gridcheckbox.jpg
 
Smarty,
Excellent. Glad I could help! Thanks for the star!


Best Regards,
Scott

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top