I have a form on which I am creating listboxes to display items fetched from a database, each of the listboxes have varying number of items. I create seven listboxes across the screen an start a row increment the width of the list box and create the next listbox etc. when I get to row 2 I need the following if it finds that a listbox height exceeds a fixed height in this case 350 then it must skip buy the width of the listbox and create it at the next column. I use the following code, but I cannot get the cloumns to get created as desired. Could someone please advise me on the best way to do this, thanks in advance. Herewith the code.
procedure Tmainfrm.CreateTickets(scount: Integer);
var
nListbox : TListBox; itemCount, TimeElapsed : integer;
start, stop, S3 : string;
begin
itemCount := 0;
nTicketNO:=TicketsQuery.FieldByName('ticketno').Value;
nCheckNo:=TicketsQuery.FieldByName('Checkno').Value;
start := formatDateTime('hh:mm:ss',TicketsQuery.FieldByName('ordertime').Value);
stop := formatDateTime('hh:mm:ss',Now);
TimeElapsed := timediffs.TimeDiffs(start,stop);
S3 := SecToTime(TimeElapsed);
PrQuery.close;
PrQuery.SQL.Clear;
PrQuery.SQL.Add('select * from ticketitems ');
PrQuery.SQL.Add('where orderno = :orderno');
PrQuery.SQL.Add('order by lineorderno,itemno');
PrQuery.Params.Items[0].AsInteger := nTicketNO;
PrQuery.Open;
itemCount := PrQuery.RecordCount;
if (((Scount-1) mod 7) = 0 ) or (lpos >= 1386 ) then
begin
inc(tpos,351); inc(nRow,1);
if (nrow = 2) then
begin
lPos := 0; //nColumn := 1;
if (nColumn = 1) and (pos1 > tpos) then
inc(lPos,231); //inc(nColumn); // else lpos := 0;
if (nColumn = 2) and (pos2 > tpos) then
inc(lPos,231); //inc(nColumn); // else lpos := 231;
if (nColumn = 3) and (pos3 > tpos) then
inc(lPos,231); //inc(nColumn); // else lpos := 462;
if (nColumn = 4) and (pos4 > tpos) then
inc(lPos,231); //inc(nColumn); // else lpos := 693;
if (nColumn = 5) and (pos5 > tpos) then
inc(lPos,231); //inc(nColumn); // else lpos := 924;
if (nColumn = 6) and (pos6 > tpos) then
inc(lPos,231) ; //inc(nColumn); // else lpos := 1155;
if (nColumn = 7) and (pos7 > tpos) then
inc(lPos,231); //inc(nColumn); // else lpos := 1386;
end;
if (nrow = 3 ) then
begin
lPos := 0; //nColumn := 1;
if (nColumn = 1) and ((pos1 > tpos) or (pos8 > tpos)) then
inc(lPos,231);
if (nColumn = 2) and ((pos2 > tpos) or (pos9 > tpos)) then
inc(lPos,231);
if (nColumn = 3) and ((pos3 > tpos) or (pos10 > tpos)) then
inc(lPos,231);
if (nColumn = 4) and ((pos4 > tpos) or (pos11 > tpos)) then
inc(lPos,231);
if (nColumn = 5) and ((pos5 > tpos) or (pos12 > tpos)) then
inc(lPos,231);
if (nColumn = 6) and ((pos6 > tpos) or (pos13 > tpos)) then
inc(lPos,231);
if (nColumn = 7) and ((pos7 > tpos) or (pos14 > tpos)) then
inc(lPos,231);
end;
{ if (nrow = 3 ) then
begin
lPos := 0; nColumn := 1;
if (nColumn = 1) and (pos8 > tpos) then
inc(lPos,231); inc(nColumn);
if (nColumn = 2) and (pos9 > tpos) then
inc(lPos,231); inc(nColumn); // else
if (nColumn = 3) and (pos10 > tpos) then
inc(lPos,231); inc(nColumn); // else
if (nColumn = 4) and (pos11 > tpos) then
inc(lPos,231); inc(nColumn); // else
if (nColumn = 5) and (pos12 > tpos) then
inc(lPos,231); inc(nColumn); // else
if (nColumn = 6) and (pos13 > tpos) then
inc(lPos,231); inc(nColumn); // else
if (nColumn = 7) and (pos14 > tpos) then
inc(lPos,231) ; inc(nColumn); // else
end; }
if (nrow = 4 ) then
begin
lPos := 0;
if (nColumn = 1) then
if pos1 > tpos then
inc(lPos,231) else lpos := 231;
if pos2 > tpos then
if (nColumn = 2) then
inc(lPos,231) else lpos := 462;
if pos3 > tpos then
if (nColumn = 3) then
inc(lPos,231) else lpos := 693;
if pos4 > tpos then
if (nColumn = 4) then
inc(lPos,231) else lpos := 924;
if pos5 > tpos then
if (nColumn = 5) then
inc(lPos,231) else lpos := 1155;
if pos6 > tpos then
if (nColumn = 6) then
inc(lPos,231) else lpos := 1386;
if pos7 > tpos then
if (nColumn = 7) then
inc(lPos,231) else lpos := 1617;
if pos8 > tpos then
if (nColumn = 1 ) then
inc(lPos,231) else lpos := 231;
if pos9 > tpos then
if (nColumn = 2) then
inc(lPos,231) else lpos := 462;
if pos10 > tpos then
if (nColumn = 3) then
inc(lPos,231) else lpos := 693;
if pos11 > tpos then
if (nColumn = 4) then
inc(lPos,231) else lpos := 924;
if pos12 > tpos then
if (nColumn = 5) then
inc(lPos,231) else lpos := 1155;
if pos13 > tpos then
if (nColumn = 6) then
inc(lPos,231) else lpos := 1386;
if pos14 > tpos then
if (nColumn = 7) then
inc(lPos,231) else lpos := 1617;
if pos15 > tpos then
if (nColumn = 1 ) then
inc(lPos,231) else lpos := 231;
if pos16 > tpos then
if (nColumn = 2) then
inc(lPos,231) else lpos := 462;
if pos17 > tpos then
if (nColumn = 3) then
inc(lPos,231) else lpos := 693;
if pos18 > tpos then
if (nColumn = 4) then
inc(lPos,231) else lpos := 924;
if pos19 > tpos then
if (nColumn = 5) then
inc(lPos,231) else lpos := 1155;
if pos20 > tpos then
if (nColumn = 6) then
inc(lPos,231) else lpos := 1386;
if pos21 > tpos then
if (nColumn = 7) then
inc(lPos,231) else lpos := 1617;
if pos22 > tpos then
if (nColumn = 1 ) then
inc(lPos,231) else lpos := 231;
if pos23 > tpos then
if (nColumn = 2) then
inc(lPos,231) else lpos := 462;
if pos24 > tpos then
if (nColumn = 3) then
inc(lPos,231) else lpos := 693;
if pos25 > tpos then
if (nColumn = 4) then
inc(lPos,231) else lpos := 924;
if pos26 > tpos then
if (nColumn = 5) then
inc(lPos,231) else lpos := 1155;
if pos27 > tpos then
if (nColumn = 6) then
inc(lPos,231) else lpos := 1386;
if pos28 > tpos then
if (nColumn = 7) then
inc(lPos,231) else lpos := 1617;
end;
if (nrow = 5 ) then
begin
lPos := 0;
if pos1 > tpos then
if (nColumn = 1) then
lpos := 231 else inc(lPos,231);
if pos2 > tpos then
if (nColumn = 2) then
lpos := 462 else inc(lPos,231);
if pos3 > tpos then
if (nColumn = 3) then
lpos := 693 else inc(lPos,231);
if pos4 > tpos then
if (nColumn = 4) then
lpos := 924 else inc(lPos,231);
if pos5 > tpos then
if (nColumn = 5) then
inc(lPos,231) else lpos := 1155;
if pos6 > tpos then
if (nColumn = 6) then
inc(lPos,231) else lpos := 1386;
if pos7 > tpos then
if (nColumn = 7) then
inc(lPos,231) else lpos := 1617;
if pos8 > tpos then
if (nColumn = 1 ) then
inc(lPos,231) else lpos := 231;
if pos9 > tpos then
if (nColumn = 2) then
inc(lPos,231) else lpos := 462;
if pos10 > tpos then
if (nColumn = 3) then
inc(lPos,231) else lpos := 693;
if pos11 > tpos then
if (nColumn = 4) then
inc(lPos,231) else lpos := 924;
if pos12 > tpos then
if (nColumn = 5) then
inc(lPos,231) else lpos := 1155;
if pos13 > tpos then
if (nColumn = 6) then
inc(lPos,231) else lpos := 1386;
if pos14 > tpos then
if (nColumn = 7) then
inc(lPos,231) else lpos := 1617;
if pos15 > tpos then
if (nColumn = 1 ) then
inc(lPos,231) else lpos := 231;
if pos16 > tpos then
if (nColumn = 2) then
inc(lPos,231) else lpos := 462;
if pos17 > tpos then
if (nColumn = 3) then
inc(lPos,231) else lpos := 693;
if pos18 > tpos then
if (nColumn = 4) then
inc(lPos,231) else lpos := 924;
if pos19 > tpos then
if (nColumn = 5) then
inc(lPos,231) else lpos := 1155;
if pos20 > tpos then
if (nColumn = 6) then
inc(lPos,231) else lpos := 1386;
if pos21 > tpos then
if (nColumn = 7) then
inc(lPos,231) else lpos := 1617;
if pos22 > tpos then
if (nColumn = 1 ) then
inc(lPos,231) else lpos := 231;
if pos23 > tpos then
if (nColumn = 2) then
inc(lPos,231) else lpos := 462;
if pos24 > tpos then
if (nColumn = 3) then
inc(lPos,231) else lpos := 693;
if pos25 > tpos then
if (nColumn = 4) then
inc(lPos,231) else lpos := 924;
if pos26 > tpos then
if (nColumn = 5) then
inc(lPos,231) else lpos := 1155;
if pos27 > tpos then
if (nColumn = 6) then
inc(lPos,231) else lpos := 1386;
if pos28 > tpos then
if (nColumn = 7) then
inc(lPos,231) else lpos := 1617;
end;
end
else
inc(lPos,231);
if lpos = 0 then nColumn := 1 else
if lpos = 231 then nColumn := 2 else
if lpos = 462 then nColumn := 3 else
if lpos = 693 then nColumn := 4 else
if lpos = 924 then nColumn := 5 else
if lpos = 1155 then nColumn := 6 else
if lpos = 1386 then nColumn := 7 ;
nListbox := TListbox.create(self);
nListbox.name := 'nListbox' + inttostr(scount);
nListbox.Left := lPos;
nListbox.top := Tpos;
nListbox.Height := (itemCount+6)*18; BoxHeight:= nListbox.Height;
// Row1
if (nrow = 1) then
begin
if (nColumn = 1) then
pos1 := nListbox.Height;
if (nColumn = 2) then
pos2 := nListbox.Height;
if (nColumn = 3) then
pos3 := nListbox.Height;
if (nColumn = 4) then
pos4 := nListbox.Height;
if (nColumn = 5) then
pos5 := nListbox.Height;
if (nColumn = 6) then
pos6 := nListbox.Height;
if (nColumn = 7) then
pos7 := nListbox.Height;
end;
// Row2
if (nrow = 2) then
begin
if (nColumn = 1) then
pos8 := nListbox.Height;
if (nColumn = 2) then
pos9 := nListbox.Height;
if (nColumn = 3) then
pos10 := nListbox.Height;
if (nColumn = 4) then
pos11 := nListbox.Height;
if (nColumn = 5) then
pos12 := nListbox.Height;
if (nColumn = 6) then
pos13 := nListbox.Height;
if (nColumn = 7) then
pos14 := nListbox.Height;
end;
// Row3
if (nrow = 3) then
begin
if (nColumn = 1) then
pos15 := nListbox.Height;
if (nColumn = 2) then
pos16 := nListbox.Height;
if (nColumn = 3) then
pos17:= nListbox.Height;
if (nColumn = 4) then
pos18 := nListbox.Height;
if (nColumn = 5) then
pos19 := nListbox.Height;
if (nColumn = 6) then
pos20 := nListbox.Height;
if (nColumn = 7) then
pos21 := nListbox.Height;
end;
// Row4
if (nrow = 4) then
begin
if (nColumn = 1) then
pos22 := nListbox.Height;
if (nColumn = 2) then
pos23 := nListbox.Height;
if (nColumn = 3) then
pos24 := nListbox.Height;
if (nColumn = 4) then
pos25 := nListbox.Height;
if (nColumn = 5) then
pos26 := nListbox.Height;
if (nColumn = 6) then
pos27 := nListbox.Height;
if (nColumn = 7) then
pos28 := nListbox.Height;
end;
nListbox.Width := 230;
nListbox.parent := ScrollBox1;
if (TimeElapsed/60 >10) and (TimeElapsed/60 < 20) then
nListbox.Color:=clYellow
else
if (TimeElapsed/60 >20) and (TimeElapsed/60 < 30) then
nListbox.Color:=$00FCCCFD
else
if TimeElapsed/60 >30 then
nListbox.Color:=clRed
else
nListbox.Color := clWhite;
nListbox.Font.Color :=clBlack;
nListbox.Hint:=intToStr(nTicketNO); //+' '+intToStr(nColumn);
nListBox.ShowHint:=True;
nListbox.OnDblClick := @LClick;
nListbox.OnClick:=@nClick;
nListbox.Font.Name := 'Tahoma';
nListbox.Font.Size := 11 ;
nListbox.Items.Clear;
nListbox.Items.Add(' Table No '+ TableNo.Caption);
nListbox.Items.Add(' '+ Clerk.Caption);
nListbox.Items.Add('----------- '+ S3+' -----------');
if PrQuery.Recordcount > 0 then
begin
while not PrQUERY.Eof do
begin
if (PrQuery.FieldByName('PartNo').Value = 'Cond') and (PrQuery.FieldByName('Redprint').Value = 'T' ) then
begin
if PrQuery.fieldbyname('Qty').Value > 1 then
begin
nListbox.Items.Add(' '+PrQuery.fieldbyname('Qty').asString+' '+PrQuery.fieldbyName('Description').asString+' '+PrQuery.fieldbyName('seatno').asString);
end
else
nListbox.Items.Add(' '+PrQuery.fieldbyName('Description').asString+' '+PrQuery.fieldbyName('seatno').asString)
end
else
nListbox.Items.Add(PrQuery.fieldbyname('Qty').asString+' '+PrQuery.fieldbyName('Description').asString+' '+PrQuery.fieldbyName('seatno').asString);
PrQuery.next;
end;
end;
PrQuery.close;
end;
if need be I can upload my project for someone to try