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

Listboxes 1

Status
Not open for further replies.

Keeper00

Programmer
Jul 17, 2003
13
US
How do I specify in a two column listbox that the second column is an image? This image will server as a checkbox, with a checked image for yes, and an empty box for unchecked, no. I also want to track these checked and unchecked records in the cursor behind the listbox, is this possible?
 
In order to do what you want you should use a grid I think...the listbox class effectuates the checkboxes with a picture property and I don't know of any way to move it over to the 2nd column...the picture property of the listbox causes pictures to be shown in the first column (not really a column, but close enough). Here is an example of using this technique (just in case the 2nd column thing isn't mandatory for you)...cut-n-paste the code below into a PRG and execute it...

PUBLIC oForm

oForm = CREATEOBJECT("clsListeckBox")

oForm.visible = .t.

READ Events

DEFINE CLASS clsListeckBox AS form

Top = 1
Left = 0
Height = 473
Width = 287
DoCreate = .T.
Caption = "Incremental Search"
WindowState = 0
Name = "clssearch"
CheckIcon = HOME() + "Graphics\Icons\Misc\MISC15.ICO"
Uncheckicon = HOME() + "Graphics\Icons\Misc\MISC13.ICO"
ShowWindow = 2

ADD OBJECT list1 AS listbox WITH ;
Height = 408, ;
Left = 12, ;
Sorted = .T., ;
Top = 48, ;
Width = 264, ;
Name = "List1", ;
RowSourceType = 2, ;
RowSource = "ListCheck"

PROCEDURE Load
LOCAL nCount, nCount2, nWordLength, sItem, nUpper, nLower
nUpper = 90 &&ASCII
nLower = 65 &&ASCII
CREATE CURSOR ListCheck (MyEntry c(35), Checked L)
FOR nCount = 1 to 250
sItem = ""
nWordLength = INT((35) * RAND( ) + 1)
FOR nCount2 = 1 TO nWordLength
sItem = sItem + CHR(INT((nUpper - nLower + 1) * RAND( ) + nLower))
ENDFOR
INSERT INTO ListCheck (MyEntry, Checked) values(sItem, .F.)
NEXT
ENDPROC

PROCEDURE Release
USE IN SELECT("ListCheck")
CLEAR EVENTS
ENDPROC

PROCEDURE ListSetup
thisform.LockScreen = .t.
LOCAL nListCount
nListCount = 1
SELECT ListCheck
SCAN All
IF ListCheck.Checked
This.list1.Picture(nListCount) = thisform.checkIcon
ELSE
This.list1.Picture(nListCount) = thisform.uncheckIcon
ENDIF
nListCount = nListCount + 1
ENDSCAN
thisform.LockScreen = .f.
ENDPROC

PROCEDURE SetCheck
LOCAL nListIndex
nListIndex = this.List1.ListIndex
IF nListIndex > 0
GO nListIndex IN "ListCheck"
IF ListCheck.Checked
this.List1.Picture(nListIndex) = thisform.uncheckIcon
ELSE
this.List1.Picture(nListIndex) = thisform.checkIcon
ENDIF
Replace ListCheck.Checked WITH !ListCheck.Checked
ENDIF
ENDPROC

PROCEDURE list1.Gotfocus()
IF DODEFAULT()
thisform.ListSetup()
ENDIF
ENDPROC

PROCEDURE list1.click()
IF LASTKEY() = 13
Thisform.SetCheck()
ENDIF
ENDPROC

PROCEDURE list1.Keypress(nKeyCode, nShiftAltCtrl)
IF nKeyCode = 13 OR nKeyCode = 32
Thisform.SetCheck()
ENDIF
ENDPROC


Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
I just noticed a little hold over stuff that I didn't clean up...sorry about that, it may be a little confusing, I was in a rush so I just modified a FAQ I wrote on incremental searching with a listbox...you should still get the idea..

Caption = "Incremental Search"
WindowState = 0
Name = "clssearch"


...should read...


Caption = "Listbox With Checkboxes"
WindowState = 0
Name = "clsListeckBox"


Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
Slighthaze,

This info was very helpful!!! One more question, how can incorporate the Moverbars into the listbox. This feature is very important or is there another way of doing that?

Thanks
 
Keeper00

You can use the picture property in the listbox to display images like a checked and unchecked box. There is a good example of this in 1001 Things you Always Wanted to Know About Visual FoxPro (KiloFox) from Hentzenwerke.
 
Keeper00,

faq184-3911

See the FAQ I created above - there were a few other little things that I messed up on a little in my haste...but the FAQ should be complete now.

As to the movers I will try to work you up an example of that in a little bit when I get some spare time.

Madtown,

I couldn't agree with you more about the 1001 Things You Always Wanted to Know About VFP. That's where I first learned how to create a listbox with checkboxes in it. That book is my all-time favorite and I would recommend it to anyone working in VFP - I would go so far as to say that that book is a must read...Marcia Akins, Andy Kramek & Rick Schummer show pure genius...where they came up with some of that stuff is beyond me sometimes, but my hat goes off to them!


Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top