Column size in listView

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I determine the the size of the column so that I could see all the
data in the listview?

I tried to use:
ListView1.Columns(i).Width = -1
And it works for the data, but if the data smaller then the column caption
then I can't see the whole caption.

How can I calculate the size (in pixels or whatever the .Width property
uses) based on a text used in the data and in the caption?
 
Hi,

I don't know if I understood you. If you are trying to measure a string take
a look at System.Graphics.MeasureString function and its paramters.

Hope that helps,
ltt19
 
Alex,

In addition to Itt19

Here a little sample from one method how you can measure that string (there
are much more, however the most important part in this sample is how you can
get that graphics object. The samples assumes mostly that you have that
already.

\\\
Dim g As Graphics = Graphics.FromHwnd(dataview1.Handle)
column.width = Cint(10 * CInt(g.MeasureString("ABCDEFGHIJKLMNOPQRSTUVWXYZ",
Me.Font).Width / 26.0!))
////

I hope this helps?

Cor
 
Alex Levi said:
ListView1.Columns(i).Width = -1
And it works for the data, but if the data smaller then the column caption
then I can't see the whole caption.

How can I calculate the size (in pixels or whatever the .Width property
uses) based on a text used in the data and in the caption?

Set the column's width to -2.
 
I have a question on this graphics object example
Where does the (dataview1.Handle) come from???
 
Back
Top