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

CheckListBox and amounts

Status
Not open for further replies.

setitup

IS-IT--Management
Jul 30, 2003
17
ZA
I will try to explain my problem as simple as possible.

What I want to do is to have a checklistbox with 2 columns for an item and a amount.

[ ]Beer $5.30
[ ]Wine $6.50
[ ]Chips $3.35

I must then be able to click selected items, and add these items' amounts to a varible, say total_amount. The amounts must be aligned like above.

Is there any easier way to do this than by manipulating strings.

Please help
Frustrated Hennie
 
What exactly is the problem?

Is it the formatting of the checklist box into two columns

or

Is it the adding of the amounts to the total_amount variable

or

Is it both these ?

Andrew
 
Hi thanx for the reply, the problem is the formatting of the listbox into two columns.

Hennie
 
If you want to have good control over the appearance of the contents of your checkbox then you should set the Style property of the checkbox to lbOwnerDrawFixed and then code a handler for the OnDrawItem event. It is not too difficult.

Suppose I have the three items in your example in a record array called food (with field names name and price) then a simple OnDrawItem event handler would look something like:
Code:
procedure TForm1.cboxDrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
var
  offset: integer;
begin
  offset := 70;
  cbox.canvas.TextOut ( Rect.Left, Rect.Top, food[index].name );
  cbox.canvas.TextOut ( Rect.Left + Offset, Rect.Top, IntToStr(food[index].price) );
end;
In practice, the offset would be calculated from the maximum length of all the food names using the TextLength function.

This should give you some ideas.

Andrew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top