Solved

ListBox, ListView items

Posted on 1998-08-26
8
459 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 1

Expert Comment

by:AndersWP
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 10

Expert Comment

by:viktornet
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now