• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 253
  • Last Modified:

Word Wrapping and lists...

Help me out please, I'm stuck!

What I want to do is to provide the user with a list of items.  Now the items are quite long so I want to be able to wrap them.  I know that MSHFlexGrids and other controls allow wrapping but the user would have to resize the rows to see all the text (either that or I would have to get into some mad coding!).

What I need is for the information to be displayed something like (and I don't know if this will look right when posted but here goes)....

1. This is the text for
   item 1
2. This is the text for
   item 2
3. This is item 3
4. This is the text for
   item 4

On top of this I need each complete item to be selectable individually, so creating a big old text box won't work.

So if any of you know of something that I've missed or failing that can help me out with coding round the problem, the points are yours.

Any ideas greatly appreciated and as an added bonus the provider of the accepted answer gets a free licence for the completed product!
  • 3
  • 3
  • 3
  • +1
1 Solution
Ryan ChongCommented:
Hi, actually i have no idea for doing this. but here is a sample that Auto Resize the column of the ListView. I don't know if it's working too for MSHFlexGrids Control..

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd _
   As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const LVM_SETCOLUMNWIDTH = &H1000 + 30
Private Const LVSCW_AUTOSIZE = -1

Private Sub Form_Click()
   AutoSizeColumns Me.lvwCoverNote
End Sub

Private Sub AutoSizeColumns(Listview As Listview, Optional ByVal UseHeader As Boolean = False)
   Dim i As Integer, lParam As Long
   If UseHeader = False Then
       lParam = LVSCW_AUTOSIZE
   End If
   For i = 0 To Listview.ColumnHeaders.Count - 1
       SendMessage Listview.hwnd, LVM_SETCOLUMNWIDTH, i, ByVal lParam
End Sub

'Try and give some comment.


Here's my suggestion (only a suggestion).  Use a listbox instead.  You could display all those results using a listbox.

Then, do this:

Create a label, autosize set to 'True'.

The code for the autosize for the listbox would be something like this:

Dim Wid as Integer
Wid = 0
For i = 0 To List1.ListCount - 1
Label1.Caption = List1.List(i) '"View" the caption's length
    If Label1.Wid > Wid Then 'Loop for longest length
    Wid = Label1.Width
    End If
Next i
List1.Width = Wid 'Set width to longest length

Hope it helps  :)

That's it!

glass cookie : )
calumscottAuthor Commented:
Sorry guys, I'm stuck for width!

This is the whole problem, I need to be able to wrap.


Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Here's a suggestion:

Use an array of textboxes.  Or checkboxes or labels or whichever you prefer.

Here's an example:

Private Sub Label1_Click(Index As Integer)
Msgbox "You've clicked onto this item: " + Label1.Caption.
End Sub

Well, to load a list of 20 items (using labels), do this:

For i = 1 To 20

Load Label1(i)
'Label1(i).Caption = [whatever - item i?]
Label1(i).Visible = True
'Stack them one above the other
Label1(i).Top = Label1(i - 1).Top + Label1(i - 1).Top + 100

Next i

That's it!

glass cookie : )

PS To change the code, simply change the name of the object.
From there, you could do the word wrap thing.
When I had a similar problem, I simply copied the text contents into the tooltiptext property at run-time.

This may not be appropriate for a grid, and would not allow editing, but does overcome the width limitation.
calumscottAuthor Commented:
Good idea.  I might give that a try, I'd love to be able to do it in a single control though.

You know in Excel when you put word wrap on a column and type in something long it automatically wraps and adjusts the rowheight.  That's the kind of thing I'm looking for.

There must be a way....
You could always overlay a label set as follows:

Wordwrap = true

'then in code
Autosize = false
Width = grid cell width
'Copy grid cell contents to label
label1.caption = gridcell.value
Autosize = true
'Reset grid height to label height
gridrow.height = label.height

(or something like this)
calumscottAuthor Commented:
That'll do nicely thank you very much!  The code is going to be a bit of a pig but it must be the answer.  Once I get it coded I'll post some samples
Thanks, calumscott.  I tried this once and it wasn't that bad, but you should definitely document it for the next poor soul to read the code.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now