Solved

ListBox, ListView items

Posted on 1998-08-26
8
469 Views
Last Modified: 2010-04-04
How to add to ListBox more than 32736 lines?
without using colums
0
Comment
Question by:lavar
8 Comments
 
LVL 5

Expert Comment

by:inter
ID: 1337810
Hi,
Are you programming with delphi 1? The delphi 2+ have max bound on items set as
MaxInt div 16 which is a huge numder...
Igor
0
 

Expert Comment

by:Jam
ID: 1337811
Hi.

The index of items is limited to 16-bit values. This means list boxes cannot contain more than 32,767 items.

This Windows(3.1, '95) limitation, not Delphi(1,2) .

Maximum capacity of TListBox not limited in Windows NT.

Solution of problem may be using TListView component. (no limitation).




0
 
LVL 10

Expert Comment

by:viktornet
ID: 1337812
Try this and you are supose to get all lines inserted if you are using Delphi2 or higher =)

procedure TForm1.Button1Click(Sender: TObject);
var
 i : integer;
begin
  for i := 0 to 32766 do
    ListBox1.Items.Add(IntToStr(i + 1));
end;

Hope this helps...

Regards,
Viktor Ivanov
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 1

Expert Comment

by:AndersWP
ID: 1337813
Why would you want such a large number of items? Surely a user will despair having to scroll through all that. Would you not be better off with some kind of hierarchy, e.g. a treeview?
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1337814
He can have many items and then use an edit box on the top so he can use Incremental searching method...It is like when you type a letter in the editbox the listbox's selected item( ItemIndex ) becomes the one whose first letters are the same as the ones in the edit box... If you need to do something like that just tell me and I'll post you a method =)

Regards,
Viktor Ivanov
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1337815
The listbox in delphi help is containing 25646 items. VB help - 7000 records. I must say I haven't seen any listbox that has so many records. Might be actually impossible as you say.
HOWEVER, in the same help window, if you click the "search" tab, the controls you will see AREN'T listboxes. They are "TextViewers", a class not documented anywhere. But this might be a sign for the disability of the simple listbox to display more the 32000 items (the lists on the "search" tab might contain much more than that).

Maybe somebody knows what are those misterious "TextViewers"?
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1337816
I tried the example I gave above and it inserts all lines in except that some of them are empty lines, maybe the last thousand or so... If I add one more item to the number as

for i := 0 to 32767 do
         ListBox1.Items.Add(IntToStr(i + 1));

then an error is displayed.....

Regards,
Viktor Ivanov
0
 
LVL 10

Accepted Solution

by:
Lischke earned 100 total points
ID: 1337817
The standard list box is indeed limited as already mentioned. I was also in need to have > 90000 items in a list (from a dictionary) and wrote a class called TVirtualListbox. The main point there is not to hold all items in the list box, but to query them only if they are required (for display, access at run time etc.). I wrote two events (OnGetItem and OnGetImage) which are called during the Paint event, but only as often as items are visible in the current client window.

One slight problem with TVirtualListbox is that you have to handle your vertical scroll events by yourself, like:

procedure TCustomVirtualListBox.WMVScroll(var Msg: TWMVScroll);

begin
  case Msg.ScrollCode of
    SB_BOTTOM        : TopIndex:=FItemCount-1;
    SB_LINEDOWN      : TopIndex:=FTopIndex+1;
    SB_LINEUP        : TopIndex:=FTopIndex-1;
    SB_PAGEDOWN      : TopIndex:=FTopIndex+FLinesInWindow;
    SB_PAGEUP        : TopIndex:=FTopIndex-FLinesInWindow;
    SB_THUMBPOSITION : TopIndex:=Round(Word(Msg.Pos)*FScrollFactor);
    SB_THUMBTRACK    : TopIndex:=Round(Word(Msg.Pos)*FScrollFactor);
    SB_TOP           : TopIndex:=0;
  end;
  Update;
  Msg.Result:=0;
end;

Another one is the fact that the parameters in WM_VSCROLL are all 16 bit, so you have to include a kind of scroll factor to be able to use more than 65535 lines. Here's the calculation and a sample for usage:

procedure TCustomVirtualListBox.SetScrollBarMax(Value: Integer);

var ScrollInfo : TScrollInfo;

begin
  if FUseExternScrollBar then FScrollbar.Max:=Value
                         else
    with ScrollInfo do
    begin
      FillChar(ScrollInfo,SizeOf(ScrollInfo),0);
      cbSize:=SizeOf(TScrollInfo);
      fMask:=SIF_RANGE;
      FlatSB_GetScrollInfo(Handle,SB_VERT,ScrollInfo);
      nMax:=Value+FLinesInWindow-2;
      // WM_SCROLL can handle only values up to ~65000
      if nMax > 65000 then
      begin
        FScrollFactor:=nMax/65000;
        nMax:=65000+FLinesInWindow;
      end
      else FScrollFactor:=1;
      FlatSB_SetScrollInfo(Handle,SB_VERT,ScrollInfo,True);
    end;
end;

//--------------------------------------------------------------------------------

procedure TCustomVirtualListBox.SetScrollBarPosition(Value: Integer);

var ScrollInfo : TScrollInfo;

begin
  if FUseExternScrollBar then FScrollbar.Position:=Value
                         else
    with ScrollInfo do
    begin
      FillChar(ScrollInfo,SizeOf(ScrollInfo),0);
      cbSize:=SizeOf(TScrollInfo);
      fMask:=SIF_POS;
      nPos:=Round(Value/FScrollFactor);
      FlatSB_SetScrollInfo(Handle,SB_VERT,ScrollInfo,True);
    end;
end;

If you don't want flat scroll bars then use SetScrollInfo instead of FlatSB_SetScrollInfo etc.

Hope this helps.

Ciao, Mike

0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question