Solved

Word Wrapping and lists...

Posted on 2001-06-03
10
239 Views
Last Modified: 2006-11-17
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!
0
Comment
Question by:calumscott
  • 3
  • 3
  • 3
  • +1
10 Comments
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
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 Const LVSCW_AUTOSIZE_USEHEADER = -2

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
   Else
       lParam = LVSCW_AUTOSIZE_USEHEADER
   End If
   For i = 0 To Listview.ColumnHeaders.Count - 1
       SendMessage Listview.hwnd, LVM_SETCOLUMNWIDTH, i, ByVal lParam
   Next
End Sub

'Try and give some comment.

0
 
LVL 8

Expert Comment

by:glass_cookie
Comment Utility
Hi!

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 : )
0
 
LVL 1

Author Comment

by:calumscott
Comment Utility
Sorry guys, I'm stuck for width!

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

Cheers

C.
0
 
LVL 8

Expert Comment

by:glass_cookie
Comment Utility
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.
0
 
LVL 8

Expert Comment

by:glass_cookie
Comment Utility
From there, you could do the word wrap thing.
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 22

Expert Comment

by:rspahitz
Comment Utility
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.
0
 
LVL 1

Author Comment

by:calumscott
Comment Utility
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....
0
 
LVL 22

Accepted Solution

by:
rspahitz earned 100 total points
Comment Utility
You could always overlay a label set as follows:

Wordwrap = true
Visible=false

'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)
0
 
LVL 1

Author Comment

by:calumscott
Comment Utility
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
0
 
LVL 22

Expert Comment

by:rspahitz
Comment Utility
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.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

763 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

11 Experts available now in Live!

Get 1:1 Help Now