Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 250
  • 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!
0
calumscott
Asked:
calumscott
  • 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 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
 
glass_cookieCommented:
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
 
calumscottAuthor Commented:
Sorry guys, I'm stuck for width!

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

Cheers

C.
0
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.

 
glass_cookieCommented:
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
 
glass_cookieCommented:
From there, you could do the word wrap thing.
0
 
rspahitzCommented:
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
 
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....
0
 
rspahitzCommented:
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
 
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
0
 
rspahitzCommented:
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

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!

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