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,
Printable View
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,
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.
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.
:)
set the width to -1 or -2
it autosizes the column
Wow! Thanks that is perfect.
heh weird:D is that documented officially anywhere?Quote:
Originally posted by marvinklein
set the width to -1 or -2
it autosizes the column
In the help. I guess it pays to look stuff up, but I can't be bothered to.
:)
hehe agreed :p I hate that msdn help that ships with vs.net. I have always had problems with it. Numerious times after installing/reinstalling I couldnt get it to work at all (it would just return an "empty index entry" message for whatever I searched). I've had the same problems with the more recent versions of MSDN help too. The website kinda works, but I'm too lazy to go there:DQuote:
Originally posted by crptcblade
In the help. I guess it pays to look stuff up, but I can't be bothered to.
:)