2 Replies - 1140 Views - Last Post: 10 February 2013 - 11:14 AM Rate Topic: -----

#1 Robert1982  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 27-January 13

Enabling multi line listing using listbox?

Posted 05 February 2013 - 06:56 AM

Hi guys,
I have a series of long text that I need to list in a listbox in VB6. However, I want it to be listed in multi line as the width of my listbox in my interface is quite narrow. It can only cater for around 45 characters per line.
This Listbox is supposed to list out the title of different documents and as such it needs to be flexible enough to cater for both text that are longer than 45 characters and shorter than 45 characters.

For instance, the two titles from two different files are as follows:

1. This is an agreement between Company A, Company B, Company C and Company D

2. Agreement 2008

Both needs to fit into the same list box on separate instances.

I cam up with something like this:

If Len(Title) > 45 Then
For x = 45 To 40 Step -1
If Mid$(Title, x, 1) = " " Then
Dialog.List5.AddItem Left(Title, x)
Dialog.List5.AddItem Right(Title, Len(Title) - x)
End If
Next
Else
Dialog.List5.AddItem arrSplitItem(4)
End If

But, it appeared it did not give me the expected results...

Can anybody tell me what's wrong with my logic? If any of you have any better ideas, do tell me. Thanks!

regards,
Robert

Is This A Good Question/Topic? 0
  • +

Replies To: Enabling multi line listing using listbox?

#2 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3177
  • View blog
  • Posts: 10,639
  • Joined: 12-December 12

Re: Enabling multi line listing using listbox?

Posted 05 February 2013 - 07:36 AM

Please put your code in code tags and indent it properly.

You haven't explained what is not working; that is, what are you expecting it to do and what does it do instead.

Anyway, you need to break out of the loop once it has found a space:

If Len(Title) > 45 Then
    For x = 45 To 40 Step -1
        If Mid$(Title, x, 1) = " " Then
            Dialog.List5.AddItem Left(Title, x)
            Dialog.List5.AddItem Right(Title, Len(Title) - x)
            'add this line..
            Exit For
         End If
    Next
Else
    Dialog.List5.AddItem arrSplitItem(4)
End If

Was This Post Helpful? 0
  • +
  • -

#3 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 572
  • View blog
  • Posts: 2,985
  • Joined: 19-May 09

Re: Enabling multi line listing using listbox?

Posted 10 February 2013 - 11:14 AM

The problem with your way of doing it is that now one file is actually more than one selection. You have a lot of work to do to simulate one selection on multiple lines. An alternative that I have used effectively (and I would suggest, probably more effectively than your solution) is to enable horizontal scrolling in a listbox. Doing this is a pretty straightforward use of the API. Google "vb6 SendMessage LB_SETHORIZONTALEXTENT" for examples.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1