|
-
May 11th, 2004, 03:24 PM
#1
Listview Column Resize
Does anyone know of an easy way to resize the ListView columns so that all the text is visible. Like when you double click on the resize bar and it automatically resizes it?
Thanks,
-
May 11th, 2004, 03:43 PM
#2
Hi.
I don't know of an easy way, but this might work:
Create a graphics object.
Loop all items in the listview
Use the MeasureString function to get the width of the each items text for that particular column.
Remember the widest.
Set the columnwidth to that.
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
May 12th, 2004, 06:29 AM
#3
You can also try API...
VB Code:
Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As IntPtr, _
ByVal wMsg As Integer, _
ByVal wParam As Integer, _
ByVal lParam As Integer) _
As Integer
Private Const LVM_FIRST As Integer = &H1000
Private Const LVM_SETCOLUMNWIDTH As Integer = (LVM_FIRST + 30)
Private Const LVSCW_AUTOSIZE As Integer = -1
Private Const LVSCW_AUTOSIZE_USEHEADER As Integer = -2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For x As Integer = 1 To 100
Dim li As New ListViewItem(StrDup(x, "I"))
li.SubItems.Add(StrDup(x, "T"))
li.SubItems.Add(StrDup(x, "4"))
ListView1.Items.Add(li)
Next
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
For Each c As ColumnHeader In ListView1.Columns
SendMessageLong(ListView1.Handle, LVM_SETCOLUMNWIDTH, c.Index, LVSCW_AUTOSIZE)
Next
End Sub
Button1_Click is just there to filll the listview with stuff.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
May 12th, 2004, 09:51 AM
#4
Registered User
set the width to -1 or -2
it autosizes the column
-
May 12th, 2004, 10:24 AM
#5
Wow! Thanks that is perfect.
-
May 12th, 2004, 12:32 PM
#6
Originally posted by marvinklein
set the width to -1 or -2
it autosizes the column
heh weird is that documented officially anywhere?
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
May 12th, 2004, 12:39 PM
#7
In the help. I guess it pays to look stuff up, but I can't be bothered to.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
May 12th, 2004, 01:23 PM
#8
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|