473,324 Members | 2,473 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Column size in listView

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
8 2391
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
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
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
> instead of create graphic. y not used keyword length!!!!!!!!!!!!

????
Nov 21 '05 #5
"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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: rmorvay | last post by:
I have successfully integrated sorting in the listview control with the following code: Private Sub ListView_ColumnClick(ByVal sender As Object, ByVal e As...
5
by: objectref | last post by:
Hi to all, i populate a ListView with data from a datareader and i just want to know the column name of the cell that the user clicks on. E.x., if the user clicks on the 2nd column, 3rd row in...
1
by: neelu | last post by:
I have four columns in listview. SR Number Part# DES Qty Weight 59 9410106800 Nut 10 0.03 60 90304ge800 Helmet 5 0.325 61 9635439604 ...
19
by: Owen T. Soroke | last post by:
Using VB.NET I have a ListView with several columns. Two columns contain integer values, while the remaining contain string values. I am confused as to how I would provide functionality to...
2
by: Just Me | last post by:
Listview is Docked=Fill I set all column widths to -2 and it works as expected if the listview needs to be too wide for the window. That is, I get an H-scrollbar and the columns are the correct...
2
by: GT | last post by:
Could someone please explain how to add images to a ListView other than in the first column?
1
by: Kimmo Laine | last post by:
Hi! I need to resize the last column in my listview control so that there won´t be horizontal scrollbar. Lets first create lv and add some items: listView1.View = View.Details;
9
by: active | last post by:
I need a control that displays a grid of rectangles. That is, like a brick wall except the rectangles are lined up. In VB6 I used such a control (may have been called FlexGrid but I'm not...
0
by: palash909 | last post by:
Visual basic version(2008) How can i change the listview column header color and font size?? 1. Listview1 body font color is black 2.Font size 9 and style is regular ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.