Solved

Word Wrapping and lists...

Posted on 2001-06-03
10
242 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 50

Expert Comment

by:Ryan Chong
ID: 6151251
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
ID: 6151414
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
ID: 6151929
Sorry guys, I'm stuck for width!

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

Cheers

C.
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 8

Expert Comment

by:glass_cookie
ID: 6151971
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
ID: 6151977
From there, you could do the word wrap thing.
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6153939
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
ID: 6160652
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
ID: 6165589
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
ID: 6170669
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
ID: 6178120
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

832 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