Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ListBox, ListView items

Posted on 1998-08-26
8
Medium Priority
?
504 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 200 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

927 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