Solved

ListBox, ListView items

Posted on 1998-08-26
8
492 Views
Last Modified: 2010-04-04
How to add to ListBox more than 32736 lines?
without using colums
0
Comment
Question by:lavar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month3 days, 13 hours left to enroll

630 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