Hello,
I use a ListView control (report view) to show the user a summary of error
messages. The width of the column that holds the error messages is such that
no horizontal scrollbar is needed. However, in some cases, the length of the
error message text is wider than the width of the column. In this case, the
text is hyphened with three dots.
I want to check the width of the error message text and if necessary,
increase the width of the ListView column. By trial and error, I know that
the amount of text that fits in a column of width 5620 twips is exactly
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ".
So, I created the following piece of code (the string Message holds a
certain error message):
With Printer
If .TextWidth(Message) >
..TextWidth("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXX") Then
ListView1.ColumnHeaders.Item(3).Width = .TextWidth(Message) /
..TextWidth("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXX") * 5620
End If
End With
Although this code functions properly, I don't think it's an outstanding
solution. Does somebody knows a better piece of code?
Thanks in advance,
Geert-Pieter 2 8128
"Geert-Pieter Hof" <g.*****@wbmt.tudelft.nl.blablabla> wrote in message news:<bg**********@news.tudelft.nl>... Hello,
I use a ListView control (report view) to show the user a summary of error messages. The width of the column that holds the error messages is such that no horizontal scrollbar is needed. However, in some cases, the length of the error message text is wider than the width of the column. In this case, the text is hyphened with three dots.
I want to check the width of the error message text and if necessary, increase the width of the ListView column. By trial and error, I know that the amount of text that fits in a column of width 5620 twips is exactly "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ".
So, I created the following piece of code (the string Message holds a certain error message):
With Printer
If .TextWidth(Message) > .TextWidth("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXX") Then
ListView1.ColumnHeaders.Item(3).Width = .TextWidth(Message) / .TextWidth("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXX") * 5620
End If
End With
Although this code functions properly, I don't think it's an outstanding solution. Does somebody knows a better piece of code?
Thanks in advance,
Geert-Pieter
You can use the TextWidth function of some controls to "test" the true
width of a certain text. Don't forget to assign the same font that you
currently use in the listview.
I use this in a loop over all my texts of a column, then select the
widest text, add some pixels for good measure, and resize the column
to that.
Robert
Private Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Private Const LVM_FIRST = &H1000
Public Sub LV_AutoSizeColumn(LV As ListView, Optional Column _
As ColumnHeader = Nothing)
Dim C As ColumnHeader
If Column Is Nothing Then
For Each C In LV.ColumnHeaders
SendMessage LV.hWnd, LVM_FIRST + 30, C.Index - 1, -1
Next
Else
SendMessage LV.hWnd, LVM_FIRST + 30, Column.Index - 1, -1
End If
LV.Refresh
End Sub
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: CBuck |
last post by:
Hi, I was wondering if it was possible to hide the first column of the datagrid (windows form control). The column that I am referring to is the column created by the control that is gray in color...
|
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...
|
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...
|
by: Richard Markus |
last post by:
How can I detect in code when a user has resized a column
in a listview control?
Thanks for the help!
Richard
|
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...
|
by: Borges |
last post by:
Hi folks,
I've got a listview with several columns, and I'm trying to
automatically resize the columns when the control gets painted. I know
there are methods for this in .NET 2 but we're not...
|
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;
|
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= |
last post by:
Hello,
I'm using the VS 2005 Express Edition for C#. In the GUI designer, when I
try to set the text alignment to anything except Left for the first column of
a ListView, it jumps back to the...
|
by: bharathreddy |
last post by:
Hi All,
I am using a listview control in my usercontrol so that it can be used in more than one form. This user control has one column extraw, so i want to make it invisible depending on the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |