Solved

ListBox, ListView items

Posted on 1998-08-26
8
465 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

895 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

19 Experts available now in Live!

Get 1:1 Help Now