×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How to put check box in List

How to put check box in List

How to put check box in List

(OP)
Hi,

Is it possible to show check box in listbox like we change in grid in place of text box.

Thanks

Saif

RE: How to put check box in List

You need two image files, one the checked-box, the other, the unchecked-box. You'll need to track the status of each item and change the image for each item based on the status.

Craig Berntson
MCSD, Visual C# MVP, www.craigberntson.com/blog

RE: How to put check box in List

Craig gave you the workaround.

Otherwise, the listbox does not compare to the grid in being a container for controls, it just has it's list and/or listitenm array, picture array, selected array etc., it even has no column sub object, but just the columnwidths property to define column sections with or without column lines.

The more typical way to use a listbox with multiple selected and unselected items is to make it a multiselect listbox and use the selected array to select items. This works best without populating it by a table/alias, though, as a workarea has just one record pointer anyway. It works, but has it's quirks, eg in programmatically setting items as selected.

You may use a grid instead of a listbox to have a checkbox and a normal text column. That should also be easy enough to do, if you don't have much code to port filling the grid instead of the listbox, eg if you used a table or alias for the listbox, you can recycle that for the grid.

Bye, Olaf.

RE: How to put check box in List

Another option would be to use the Treeview or Listview ActiveX control in place of a listbox. These behave very similarly to listboxes. They both support checkboxes natively.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: How to put check box in List

If you still want to use listbox and you want to add checkbox objects (not only pictures), you can use RowSourceType=10. But the graphic images must be managed like was already mentioned.

If I'm correct, the Picture property of the listbox can be used as an array (Picture(1), Picture(2),...) for RowSourceType=0,1,5 and 10
For RowSourceType=2,3 and 6 only Picture has effect, not Picture(1), Picture(2),...

I made a short test.

CODE --> Foxpro

PUBLIC ofrm
DO genpict
ofrm=CREATEOBJECT("MyForm")
ofrm.show()

DEFINE CLASS MyForm as Form
	ocol=Null
	ADD OBJECT lst as Listbox WITH width=300,multiselect=1
	PROCEDURE init
		This.ocol=CREATEOBJECT("collection")
		FOR lni=1 TO 5
			This.ocol.Add(CREATEOBJECT("mycheckbox"))
			This.ocol.item(lni).Caption="Item "+TRANSFORM(lni)
			This.ocol.item(lni).nListItem=lni
			This.ocol.item(lni).oList=This.lst
			This.ocol.item(lni).value2="Col 2 item "+TRANSFORM(lni)
			This.ocol.item(lni).value3="Third col item "+TRANSFORM(lni)
		NEXT
		This.lst.RowSourceType=10
		This.lst.ColumnCount=3
		This.lst.ColumnWidths="100,75,100"
		This.lst.RowSource="ThisForm.ocol,caption,value2,value3"
		FOR lni=1 TO 5
			This.lst.Picture(lni)="uncheck.bmp"
		NEXT
	ENDPROC
	PROCEDURE lst.click
		FOR lni=1 TO This.ListCount
			ThisForm.ocol.item(lni).Value=This.selected(lni)
		NEXT
	ENDPROC
	PROCEDURE lst.keypress
		LPARAMETERS nkey,nshift
		IF INLIST(nkey,13,32)
			NODEFAULT
			DODEFAULT(nkey,nshift)
			FOR lni=1 TO This.ListCount
				ThisForm.ocol.item(lni).Value=This.selected(lni)
			NEXT
		ENDIF
	ENDPROC
	PROCEDURE destroy
		This.ocol=Null
	ENDPROC
ENDDEFINE

DEFINE CLASS MyCheckbox as checkbox
	Picture="uncheck.bmp"
	DownPicture="check.bmp"
	style=1
	value=.F.
	nListItem=0
	oList=Null
	value2=""
	value3=""
	PROCEDURE interactivechange
		IF VARTYPE(This.oList)="O" AND !ISNULL(This.oList) AND This.nListItem>0
			This.oList.Picture(This.nListItem)=IIF(This.Value,This.DownPicture,This.Picture)
		ENDIF
	ENDPROC
	PROCEDURE programmaticchange
		IF VARTYPE(This.oList)="O" AND !ISNULL(This.oList) AND This.nListItem>0
			This.oList.Picture(This.nListItem)=IIF(This.Value,This.DownPicture,This.Picture)
		ENDIF
	ENDPROC
ENDDEFINE

PROCEDURE GenPict
	LOCAL lcFile,oImage,oGr,oFillColor,oLineColor,oPen,nHeight,nBkColor,nForeColor
	nBkColor=RGB(255,255,255)
	nForeColor=0
	nHeight=14
		
	lcFile="uncheck.bmp"
	oImage = Newobject('Gpbitmap',Home(1)+'ffc/_gdiplus.vcx')
	oImage.Create(m.nHeight,m.nHeight)
	oGr = Newobject('GpGraphics',Home(1)+'ffc/_gdiplus.vcx')
	oGr.CreateFromImage(oImage)
	oFillColor = Newobject( 'GpColor',Home(1)+'ffc/_gdiplus.vcx','', nBkColor%256,FLOOR(nBkColor%(256*256)/(256)),FLOOR(nBkColor/(256*256)) ) 
	oFillColor.set(nBkColor%256,FLOOR(nBkColor%(256*256)/(256)),FLOOR(nBkColor/(256*256)))
	oGr.Clear(oFillColor)
	oLineColor = Newobject( 'GpColor',Home(1)+'ffc/_gdiplus.vcx','', nForeColor,FLOOR(nForeColor%(256*256)/(256)),FLOOR(nForeColor/(256*256)) )
	oPen = Newobject('GpPen', Home(1)+'ffc/_gdiplus.vcx' )
	oPen.Create( m.oLineColor, 1 )
	oGr.DrawRectangle(oPen, 2,2, m.nHeight-5,m.nHeight-5)
	oImage.Savetofile( lcFile, "image/bmp")
		
	lcFile="check.bmp"
	oGr.DrawLine(oPen, 2,2, m.nHeight-4,m.nHeight-4)
	oGr.DrawLine(oPen, m.nHeight-3,2,2,m.nHeight-3)
	oImage.Savetofile( lcFile, "image/bmp")
ENDPROC 

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania

RE: How to put check box in List

(OP)
Thanks Mr.Vilhelm-Ion Praisach for such a nice example I will go through it.

Thanks Mr.Mike for the idea, but I want to display the records of the delivered/undelivered items of Delivery Orders in list and wanted to show the check box (checked) which is delivered and (Unchecked) which is not delivered. Otherwise, it showing .T. and .F. respectively.
Grid is good alternate.

Thanks

Saif

RE: How to put check box in List

Quote (Saif)

Thanks Mr.Mike for the idea, but I want to display the records of the delivered/undelivered items of Delivery Orders in list and wanted to show the check box (checked) which is delivered and (Unchecked) which is not delivered.

Well, that's exactly what I had in mind when I suggested using a Listview or Treeview. With those controls, it is easy to display the checkbox and to bind it to a logical field in the way you describe.

However, I'm not suggesting it's the best solution. Personally, I would probably use a grid. If nothing else, it has the advantage of being a native VFP control.

But if you (or anyone else) is interested in seeing how to do it with a Listview / Treeview, I am happy to post step-by-step instructions.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: How to put check box in List

I have no experience with Listview so I am very interested. Thank you in advance.

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania

RE: How to put check box in List

Quote (alisaif)

I want to display the records of the delivered/undelivered items of Delivery Orders in list and wanted to show the check box (checked) which is delivered and (Unchecked) which is not delivered

Technically speaking, this is dead wrong use of the checkbox UNLESS the user can click the checkbox to toggle it.

A checkbox is a USER control. They use it to turn something on or off. If you use it for something else then they won't have certainty about what other checkboxes in your application (and others) do.

There's an example of this in VFP itself. In the menu designer's General Options dialog there are checkboxes for Setup code and Cleanup code. They're not on/off toggles. They open a window. It's completely wrong use of a checkbox and it confuses me every time I use it (which is compounded because I tend not to use it very often).

Think long before you use a control the wrong way.

RE: How to put check box in List

Dan, you are completely correct. I hadn't realised that was what Saif was asking. I thought he wanted to let the user toggle the true/false state. If he just wants to display the state, he should use a tick (checkmark) to indicate true, with the absence of a tick to show fasle. In fact, you can do that without resorting to images, provided you know your users have a font installed that includes a checkmark (Wingdings or Dingbats or something similar).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: How to put check box in List

Quote (Vilhelm-Ion Praisach)

I have no experience with Listview so I am very interested.

Hi Vilhelm-Ion,

Keep in mind that a Listview might not be the ideal control in this particular case, for the reasons we have discussed (especially in light of what Dan said above about using a checkbox only to let the user toggle the status). But let me give you a quick walk-through, in the hope that you or others will find it useful.

Some time ago, I created a little wrapper class for the Listview, called SimpleList. Its aim is to hide most of the details of using the Listview, and especially to make it easy to bind the control to a cursor. You might want consider using it. If so, feel free to download a copy from here.

Next, drop the SimpleList on a form, and give it a sensible name. Next, set properties, as follows (I'll assume you will do this in the Init):

CODE -->

WITH THIS
  .cAlias = "Orders"  && alias of table or cursor to bind to the control
  .cData = "Order_ID" && a character field in the cursor that you want to display
  
  .cCheckField = "Delivered"  && a logical field in the cursor that you want to 
                              && map to the checkbox
  .lUpdateCheckbox = .T. && says that, when the user toggles the checkbox, 
                       && this will also toggle the logical field
  .lCheckBoxes = .T.   && a master switch to enable / disable the checkbox

  .PopulateList       && go ahead and display the data
ENDWITH 

That's about it. The download includes a documentation file which describes the other features of the control.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: How to put check box in List

Just test it and it seems very easy to use smile
Thank you again, Mr. Mike Lewis.

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania

RE: How to put check box in List

If you merely want to display delivered/undelivered status, also look at Listbox.disableditembackcolor and itembackcolor, Adding delivered items as "\item" instead of "item" you can make use of the disabled item colors. Disabling also means they can't be selected (due to a listbox bug the can be, if using multiselect from/to two enabled items before and after the disabled ones), which might be bad or good, in case only the undelivered items should be selectable eg for tracking.

I'd go for a dynamicbackcolor in a grid, though. That can be set without enabling/disabling items. This gives much better visualisation of the state than just a checkbox.

Bye, Olaf.

RE: How to put check box in List

Quote (Olaf)

I'd go for a dynamicbackcolor in a grid, though.

I'd go for DynamicCurrentControl. That's partly because the presence or absence of a tick in the "Delivered" column has a more obvious meanding than a change of colour. And partly because I try to avoid using colours as part of the core functionality, in case any of the users are colour blind.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: How to put check box in List

I agree with Mike here. I avoid color. I once had a situation where my two immediate bosses (!) were both color blind but in completely different ways. I *had* to learn to make things clear without color.

RE: How to put check box in List

Well, I disagree, because then we could also all develop for the least common denominator, there are tools for people with disabilities in Windows (Ease of Access), you can make colors configurable but even green color blind can distinguish between clear green and red.

There are other arguments against color, eg too much color would be overwhelming and destroy coprporate identity design of an application.

Anyway you can combine dynamic colors with other dynamic properties, also dynamicfont... properties: ...name, ...size, ...bold, ...italic. Again combining too many of them will not look good and be informative.

Another thing you can of course do is sort by delivery status and fill two lists or show items left/right aligned. All of this is easier in a grid than in a listbox.

A checkbox is a good interface showing status too, especially in the form of a checklist, but then again it's also about toggling the state to "done", maybe only allowing the first unchecked box to be ticked.

Bye, Olaf.

RE: How to put check box in List

Olaf, it's not always possible for these tools to change color. Take an image for example.

Also, if the application is used by the US Government, it must meet regulations of the Americans with Disabilities Act. I know of one case where a company was denied a contract because the colors on their PowerPoint slides during their sales pitch did not comply. In fact, the government cut short their presentation and told them to leave.

Craig Berntson
MCSD, Visual C# MVP, www.craigberntson.com/blog

RE: How to put check box in List

We're not talking of images here, but of self defined colors of a grid.
Anyway, Saif will decide and consider anything needed for his country and laws. Everything has been said.

Bye, Olaf.

RE: How to put check box in List

(OP)
Thanks for this healthy discussion, I am trying alternate solution with the help of your suggestions.

Saif

RE: How to put check box in List

Saif, perhaps you can let us know which option you eventually go for, as this could be of interest to other people with a similar neeed.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: How to put check box in List

(OP)
I am still interested in check box and the list should be read only.
I open one field (inv c(8)) in delivery order table and value is replaced with invoice no. once the invoice is generated.
So, I want to put the syntax something like this.

CODE -->

This.Parent.ContList.List1.RowSource = 'DoView'
This.Parent.ContList.List1.RowSourceType = 2
This.Parent.ContList.List1.Picture = Iif(! Empty(inv),'\GRAPHICS\ICONS\CHECKBOX_CHECKED.BMP','\GRAPHICS\ICONS\UnCHECKBOX_CHECKED.BMP') 

Thanks

Saif

RE: How to put check box in List

Picture is not a Dynamic property you can fill with an IIF, you have to go through all items and set that in Picture[n]. It was already mentioned it's an array property with an element per Item.

Bye, Olaf.

RE: How to put check box in List

Saif,

That won't work. What you'll get is the same iamge in every item.

To make it work, you need to treat the items in the list like an array. You can then indivually address each item according to the contents of the corresponding record. Something like this:

CODE -->

SELECT DoView
lnRow = 1
this.Parent.ContList.List1.RowSourceType = 0
SCAN
  this.Parent.ContList.List1.AddItem(Order_ID)    && or whatever character field you want to display
  this.Parent.ContList.List1.Picture(lnRow) = ;
     IIF(! EMPTY(inv),'\GRAPHICS\ICONS\CHECKBOX_CHECKED.BMP','\GRAPHICS\ICONS\UnCHECKBOX_CHECKED.BMP')
  lnRow = lnRow + 1
ENDSCAN 


Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: How to put check box in List

(OP)
Hi

Thanks for the reply! It is very very slow.

Saif

RE: How to put check box in List

How many records are you putting into the listbox?
Of course this takes more time compared to setting a rowsourcetpye alias and a table or cursor as rowsource, because you need to really create all the items.
The grid is the better choice in that case.

Bye, Olaf.

RE: How to put check box in List

A listbox is not a good object for handling many items.
If your table has no more than 500 records, you can try RowSourceType=5 amd SELECT ... INTO ARRAY instead of SCAN... ENDSCAN (but I didn't noticed a gain in speed)
If you have 501 items, then Picture[1] is ignored.
If you have 502 items, then Picture[1] and Picture[2] is ignored, and so on.

For the solution proposed by Mr. Mike Lewis, with RowSourceType=0, I tried a cursor with 20000 records and I didn't noticed this problem.

CODE --> Foxpro

PUBLIC ofrm
DO GenPict
ofrm=CREATEOBJECT("MyForm")
ofrm.show()

DEFINE CLASS MyForm as Form
	DIMENSION MyArray(1)
	ADD OBJECT lst1 as Listbox WITH width=200,columncount=2,columnwidths='75,125'
	
	PROCEDURE load
		CREATE CURSOR Invoices (inv c(8),cust C(20))
		LOCAL lni
		FOR lni=1 TO 500
			IF m.lni%7=0
				APPEND BLANK
			ELSE
				INSERT INTO Invoices VALUES ('Inv '+TRANSFORM(m.lni),'Cust '+TRANSFORM(m.lni%5+1))
			ENDIF
		NEXT
	ENDPROC
	PROCEDURE Init
		LOCAL lni
		SELECT * FROM Invoices INTO ARRAY ThisForm.MyArray
		This.lst1.RowSourceType=5
		This.lst1.RowSource='ThisForm.MyArray'
		FOR lni=1 TO This.lst1.ListCount
			This.lst1.Picture[m.lni]=IIF(EMPTY(This.lst1.List[m.lni,1]),"uncheck.bmp","check.bmp")
		NEXT
	ENDPROC
	PROCEDURE lst1.destroy
		LOCAL lni
		FOR lni=1 TO This.ListCount
			IF FILE(This.Picture[m.lni])
				ERASE (This.Picture[m.lni])
			ENDIF
		NEXT
	ENDPROC
ENDDEFINE


PROCEDURE GenPict
		LOCAL lcFile,oImage,oGr,oFillColor,oLineColor,oPen,oFontFam,oFont,oStringFormat,oBounds,oBrush,nHeight,nBkColor,nForeColor
		nBkColor=RGB(255,255,255)
		nForeColor=0
		nHeight=14
		
		lcFile="uncheck.bmp"
		oImage = Newobject('Gpbitmap',Home(1)+'ffc/_gdiplus.vcx')
		oImage.Create(m.nHeight,m.nHeight)
		oGr = Newobject('GpGraphics',Home(1)+'ffc/_gdiplus.vcx')
		oGr.CreateFromImage(oImage)
		oFillColor = Newobject( 'GpColor',Home(1)+'ffc/_gdiplus.vcx','', nBkColor%256,FLOOR(nBkColor%(256*256)/(256)),FLOOR(nBkColor/(256*256)) ) 
		oFillColor.set(nBkColor%256,FLOOR(nBkColor%(256*256)/(256)),FLOOR(nBkColor/(256*256)))
		oGr.Clear(oFillColor)
		oLineColor = Newobject( 'GpColor',Home(1)+'ffc/_gdiplus.vcx','', nForeColor,FLOOR(nForeColor%(256*256)/(256)),FLOOR(nForeColor/(256*256)) )
		oPen = Newobject('GpPen', Home(1)+'ffc/_gdiplus.vcx' )
		oPen.Create( m.oLineColor, 1 )
		oGr.DrawRectangle(oPen, 2,2, m.nHeight-5,m.nHeight-5)
		oImage.Savetofile( lcFile, "image/bmp")
		
		lcFile="check.bmp"
		oGr.DrawLine(oPen, 2,2, m.nHeight-4,m.nHeight-4)
		oGr.DrawLine(oPen, m.nHeight-3,2,2,m.nHeight-3)
		oImage.Savetofile( lcFile, "image/bmp")
		
		RETURN lcFile
ENDPROC 

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania

RE: How to put check box in List

Quote:

It is very very slow.

It will only be slow if the listbox has many items. As others have said, a listbox is not the ideal tool if there are a large number of items in the list - somewhere between 25 and 50 items should be the maximum. If you keep below that figure, the method I suggested will not be particularly slow - unless there are other factors in play that we don't know about.

This isn't just a performance issue. If your aim is to let the user make a selection from the listbox, then you make it harder for them to do that if you have more than a couple of dozen items to choose from. In that case, you wil need some sort of search or filter to narrow down the choices. That applies equally to a grid. But at least a grid will load much faster if you realy must have a large number of items.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: How to put check box in List

(OP)
It is around 18900+ records purpleface

I think I must switch to Grid Option without any further delay.

Saif

RE: How to put check box in List

Quote:

It is around 18900+ records

Believe me, that is far too many for a listbox - even without the images.

Even for a grid, that is a large number of records to show at one time. The grid will handle it easily, but I would question the user interface issues involved with displaying such a large amount of information in a single control.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: How to put check box in List

Considering the delivery status you could skip all data that is completely delivered for at least a month. That's of no interest anymore.
If you show this for orderitems you should consider seperating that into a listbox or grid for orders and one to show the details of one order only, the currently selected order in the first list.
Also filter for any order, which is already completed for a long enough time for the user to also see just currently finished orders for their confirmation, perhaps.

If you really have such an amount of current orders partly delivered, than congrats.

Bye, Olaf.

RE: How to put check box in List

(OP)
Actually delivery order is just an example, same way I want to display the Sales Invoice records throughout the year. It is because I kept the date (from-to) open and user can enter any date in order to track the customer record.

Please suggest which is the best option in this circumstance?

Saif

RE: How to put check box in List

You can always limit the amount of data you display with TOP clause.

Anyway the suggestion to accumulate a major list and show just one order, one invoice,one xyz completely can always be applied.

Bye, Olaf.

RE: How to put check box in List

(OP)
Thanks for the suggestion!

Saif

RE: How to put check box in List

Saif,

I suggest you start by showing all the data - in a grid - but then give the user various options for filtering it. For example, you might let them filter by date of order (this month's orders, last month's orders, year-to-date, specific dates, etc); or by product, or value, or whatever makes sense in your application. And combine the filters so that they can use them in any combination.

Also, let them specify which column the grid is to be sorted on. It would be nice to let them click on a column header to sort on that column, but other mechanisms are also possible. And, once they have the grid in a given order, let them do an incremental search on the column in question.

Alternatively, take a completely different approach: Start by having them search for the orders (or whatever) they are interested in; then use the grid to display the records that match the search criteria.

These are just suggestions. You now your application - and your users - better than we do, so do whatever you think would work best.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: How to put check box in List

(OP)
Thanks for the valuable suggestion

Quote:

I suggest you start by showing all the data - in a grid - but then give the user various options for filtering it. For example, you might let them filter by date of order (this month's orders, last month's orders, year-to-date, specific dates, etc); or by product, or value, or whatever makes sense in your application. And combine the filters so that they can use them in any combination.

I will do the same and doing the same even for the list, now I have to change the list to grid.

Thanks

Saif

RE: How to put check box in List

you can speed up the whole process by first assigning the picture image for the most frequent values.
In the following demo the empty() is six time less frequent.

CODE --> Foxpro

PUBLIC ofrm
DO genpict
ofrm=CREATEOBJECT("MyForm")
ofrm.show()

DEFINE CLASS MyForm as Form
	ADD OBJECT lst2 as Listbox WITH width=200,columncount=2,columnwidths='75,100'
	PROCEDURE load
		LOCAL lni
		CREATE cursor cTmp (inv c(9),cust C(20))
		FOR lni=1 TO 20000
			IF lni%7<>0
				INSERT INTO cTmp (inv,cust ) VALUES ('Inv '+TRANSFORM(m.lni),'Cust '+TRANSFORM(m.lni%5))
			ELSE
				APPEND BLANK
			ENDIF
		NEXT
		GO TOP
	PROCEDURE Init
		LOCAL lni
		This.lst2.Picture="check.bmp" && First I set the most frequent picture
		SELECT cTmp
		lni=0
		SCAN
			lni=m.lni+1
			This.lst2.AddItem(inv)
			This.lst2.LIST(This.lst2.NewIndex,2)=cust
			If Empty(inv) && here I set only the less frequent picture
				This.lst2.Picture[m.lni]="uncheck.bmp"
			ENDIF
		ENDSCAN
	ENDPROC
	
	PROCEDURE lst2.destroy
*!*			LOCAL lni
*!*			FOR lni=1 TO This.ListCount
*!*				IF FILE(This.Picture[m.lni])
*!*					ERASE (This.Picture[m.lni])
*!*				ENDIF
*!*			NEXT
		IF FILE("check.bmp")
			ERASE check.bmp
		ENDIF
		IF FILE("uncheck.bmp")
			ERASE uncheck.bmp
		ENDIF
	ENDPROC
ENDDEFINE

PROCEDURE GenPict
	LOCAL lcFile,oImage,oGr,oFillColor,oLineColor,oPen,nHeight,nBkColor,nForeColor
	nBkColor=RGB(255,255,255)
	nForeColor=0
	nHeight=14
		
	lcFile="uncheck.bmp"
	oImage = Newobject('Gpbitmap',Home(1)+'ffc/_gdiplus.vcx')
	oImage.Create(m.nHeight,m.nHeight)
	oGr = Newobject('GpGraphics',Home(1)+'ffc/_gdiplus.vcx')
	oGr.CreateFromImage(oImage)
	oFillColor = Newobject( 'GpColor',Home(1)+'ffc/_gdiplus.vcx','', nBkColor%256,FLOOR(nBkColor%(256*256)/(256)),FLOOR(nBkColor/(256*256)) ) 
	oFillColor.set(nBkColor%256,FLOOR(nBkColor%(256*256)/(256)),FLOOR(nBkColor/(256*256)))
	oGr.Clear(oFillColor)
	oLineColor = Newobject( 'GpColor',Home(1)+'ffc/_gdiplus.vcx','', nForeColor,FLOOR(nForeColor%(256*256)/(256)),FLOOR(nForeColor/(256*256)) )
	oPen = Newobject('GpPen', Home(1)+'ffc/_gdiplus.vcx' )
	oPen.Create( m.oLineColor, 1 )
	oGr.DrawRectangle(oPen, 2,2, m.nHeight-5,m.nHeight-5)
	oImage.Savetofile( lcFile, "image/bmp")
		
	lcFile="check.bmp"
	oGr.DrawLine(oPen, 2,2, m.nHeight-4,m.nHeight-4)
	oGr.DrawLine(oPen, m.nHeight-3,2,2,m.nHeight-3)
	oImage.Savetofile( lcFile, "image/bmp")
ENDPROC 

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania

RE: How to put check box in List

(OP)
Thanks again for the nice example, but I switched to grid which now consist of several forms like Sales Order, Despatch Order, Delivery Challans, Sales Invoice, Sales Return and FOC. This is a good example for future use.

Thanks

Saif

RE: How to put check box in List

Another advantage of the grids dynamicproperties: Even if you couldn't embed a checkbox, you could embed two image controls in a column and use dynamiccurrentcontrol to switch between pictures, as Mike suggested right after I suggested dynamicbackcolor. The trick with the Picture property setting the whole array and then only reset the few pictures, that are different, is still taking much more time than that.

Bye, Olaf.

RE: How to put check box in List

(OP)
Thanks to reveal a valuable point into light.

Saif

RE: How to put check box in List

I've found a way to use different pictures when Rowsource=2 (alias), but the limit of 500 rows remains.
The same limit I found for RowSource=5 (array).

The trick is to place the setting picture in the paint method.
To avoid unnecessary calling of the FirstPaint method, I added a new form property, named lFirstPaint.

CODE --> Foxpro

PUBLIC ofrm
DO GenPict
ofrm=CREATEOBJECT("MyForm")
ofrm.show()

DEFINE CLASS MyForm as Form
	ADD OBJECT lst1 as Listbox WITH width=200,columncount=2,columnwidths='75,125',RowSourceType=2,RowSource="Invoices"

************ The new property and procedures
	lFirstPaint=.F.
	PROCEDURE paint
		IF !This.lFirstPaint
			This.FirstPaint
			This.lFirstPaint=.T.
		ENDIF
	ENDPROC
	PROCEDURE FirstPaint
		SELECT Invoices
		SCAN
			This.lst1.Picture[RECNO("Invoices")]=IIF(EMPTY(invoices.inv),"uncheck.bmp","check.bmp")
		ENDSCAN
		GO TOP
	ENDPROC
*************
	
	PROCEDURE load
		CREATE CURSOR Invoices (inv c(8),cust C(20))
		LOCAL lni
		FOR lni=1 TO 500 && for 501 the first row show no picture, for 502 the first two rows and so on
			IF m.lni%7=0
				APPEND BLANK
			ELSE
				INSERT INTO Invoices VALUES ('Inv '+TRANSFORM(m.lni),'Cust '+TRANSFORM(m.lni%5+1))
			ENDIF
		NEXT
	ENDPROC

	PROCEDURE lst1.destroy
		LOCAL lni
		FOR lni=1 TO This.ListCount
			IF FILE(This.Picture[m.lni])
				ERASE (This.Picture[m.lni])
			ENDIF
		NEXT
	ENDPROC
ENDDEFINE


PROCEDURE GenPict
		LOCAL lcFile,oImage,oGr,oFillColor,oLineColor,oPen,oFontFam,oFont,oStringFormat,oBounds,oBrush,nHeight,nBkColor,nForeColor
		nBkColor=RGB(255,255,255)
		nForeColor=0
		nHeight=14
		
		lcFile="uncheck.bmp"
		oImage = Newobject('Gpbitmap',Home(1)+'ffc/_gdiplus.vcx')
		oImage.Create(m.nHeight,m.nHeight)
		oGr = Newobject('GpGraphics',Home(1)+'ffc/_gdiplus.vcx')
		oGr.CreateFromImage(oImage)
		oFillColor = Newobject( 'GpColor',Home(1)+'ffc/_gdiplus.vcx','', nBkColor%256,FLOOR(nBkColor%(256*256)/(256)),FLOOR(nBkColor/(256*256)) ) 
		oFillColor.set(nBkColor%256,FLOOR(nBkColor%(256*256)/(256)),FLOOR(nBkColor/(256*256)))
		oGr.Clear(oFillColor)
		oLineColor = Newobject( 'GpColor',Home(1)+'ffc/_gdiplus.vcx','', nForeColor,FLOOR(nForeColor%(256*256)/(256)),FLOOR(nForeColor/(256*256)) )
		oPen = Newobject('GpPen', Home(1)+'ffc/_gdiplus.vcx' )
		oPen.Create( m.oLineColor, 1 )
		oGr.DrawRectangle(oPen, 2,2, m.nHeight-5,m.nHeight-5)
		oImage.Savetofile( lcFile, "image/bmp")
		
		lcFile="check.bmp"
		oGr.DrawLine(oPen, 2,2, m.nHeight-4,m.nHeight-4)
		oGr.DrawLine(oPen, m.nHeight-3,2,2,m.nHeight-3)
		oImage.Savetofile( lcFile, "image/bmp")
		
		RETURN lcFile
ENDPROC 

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania

RE: How to put check box in List

(OP)
As per the suggestions I have replaced the listbox with grid and it is running very well as per my requirement for the bulky data. But this is a nice example to remember.

Thanks for this!

Saif

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close