By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,204 Members | 1,161 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,204 IT Pros & Developers. It's quick & easy.

Column size in listView

P: n/a
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?
Nov 21 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
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 Levi" wrote:
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?

Nov 21 '05 #2

P: n/a
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
Nov 21 '05 #3

P: n/a
instead of create graphic. y not used keyword length!!!!!!!!!!!!

Cor Ligthert wrote:
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


Nov 21 '05 #4

P: n/a
> instead of create graphic. y not used keyword length!!!!!!!!!!!!

????
Nov 21 '05 #5

P: n/a
"Alex Levi" <Al******@discussions.microsoft.com> schrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #6

P: n/a
good work. but need better.

Herfried K. Wagner [MVP] wrote:
"Alex Levi" <Al******@discussions.microsoft.com> schrieb:

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.


Nov 21 '05 #7

P: n/a
"Supra" <su*****@rogers.com> schrieb:
good work. but need better.


?!?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #8

P: n/a
I have a question on this graphics object example
Where does the (dataview1.Handle) come from???

--
thank You
"Cor Ligthert" wrote:
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
Apr 1 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.