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!

ListBox With CheckBox

Status
Not open for further replies.

admdev

Programmer
May 17, 2006
56
US
Hi all,

Hope somebody can help.

I am building an application, which has a list box with a check box. I am getting the desired results, except that when checking a different check box, I would like the rest to be unchecked. I followed the "How To Add a Check Box to a List in Visual FoxPro" walk through on Microsoft's web site.


Additionally, I am calling an INPUTBOX from one of the items in the listbox. When the INPUTBOX is displayed, the checked box is replaced with the unchecked one on the item clicked. I would like this box to remain checked after the INPUTBOX is displayed.

Any help would be greatly appreciated.

Thanks.
 
When you want only one item in a group to be selected, you usually use an option group rather than checkboxes. Is there a reason you can't just use an ordinary listbox? That already has the behavior you want.

I just looked at the KB article you pointed to. Seems to me what you'll have to do is, when you're changing to the checked bmp on one item, loop through all the others and change to the unchecked bmp.

Tamar
 
TamarGranor,

Thanks for the reply.

The reason I want to use the list box with the check box is because the list of items can change at any time. I am populating the items from a SQL database. What you suggested about looping is exactly what I thought about doing; however, I did not know how to do it.

Could you provide an example?

Thanks.
 
But a listbox can handle a changing list. Why do you need a checkbox there, as well?

To loop through the items in a listbox, use code like:

FOR nItem = 1 to THIS.ListCount
* Address the item as This.List[ m.nItem ]
ENDFOR

Tamar
 
For cosmetic reasons only. I want the users to see they have actually checked something. Although, I could only highlight the selected record, which is already working. But I wanted to make it look as if they were checking a box besides highlighting the selected item.

This is my code.

IF LASTKEY()!= 5 AND LASTKEY() != 24
IF This.Parent.pItemSel(This.ListItemID)=0
This.Picture(This.ListItemID)= SYS(2003) + '\Images\checkbx.bmp'
This.Parent.pItemSel(This.ListItemID)=1
ELSE
IF This.Parent.pItemSel(This.ListItemID)=1

This.Picture(This.ListItemID)=SYS(2003) + '\Images\box.bmp'

THIS.ItemBackColor= RGB(255,255,255)
This.Parent.pItemSel(This.ListItemID)=0
ENDIF
ENDIF
ENDIF

When looping, how should I replace the image?

Thanks for your help.
 
The property that refers to the image is This.Picture[nItem], so you can just change that in your loop.

Tamar
 
TamarGranor,

It's working now. Thanks for your help!

Now, when clicking one of the items, I open the INPUTBOX to enter some text. When the INPUTBOX is closed, the check box is reset to the empty one. Any idea why is doing that?

Thanks.
 
Below is the code.

LOCAL lcfabother
IF LASTKEY()!= 5 AND LASTKEY() != 24

FOR nItem = 1 to THIS.ListCount
DO CASE
CASE This.Parent.pItemSel(This.ListItemID)=0
FOR nItem = 1 to THIS.ListCount
IF THIS.ListItemId=nItem Then
This.Picture(nItem)= SYS(2003) + '\Images\checkbx.bmp'
ELSE
This.Picture(nItem)=SYS(2003) + '\Images\box.bmp'
ENDIF

ENDFOR
This.Parent.pItemSel(This.ListItemID)=1

CASE This.Parent.pItemSel(This.ListItemID)=1
This.Picture(This.ListItemID)=SYS(2003) + '\Images\box.bmp'
THIS.ItemBackColor= RGB(255,255,255)
This.Parent.pItemSel(This.ListItemID)=0
ENDCASE
ENDFOR

ENDIF

IF cursor.field1="Other" Then
lcfabother=INPUTBOX("Enter a reason","Reason Required",'',0,'','')

ENDIF

Thanks.
 
why don't u use a grid? and put a checkbox control in it.

get the data from the sql into a cursor, and just put the recordsource property to the grid.

and then, scan thru the cursor to figure out the checked (logical field) records?



Ali Koumaiha
Wireless Toyz
Farmington Hills, Michigan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top