Re: Listview size

Tech-Archive recommends: Speed Up your PC by fixing your registry



JL,
There should not be any downsides that I know of. Internally, the .NET ListView is making the same API calls, you just don't know it.
I'm verse with the ListView API calls because I wrote my own .NET ListView control. So I browsed around through the LVM_'s definitions looking for one to do what you wanted.
I'm glad it worked for you. You hadn't responded to my 2nd post so I thought it wasn't what you were needing (again like in 1st post).


Jason Newell, MCAD
Software Engineer


J L wrote:
Hi Jason,
OMG...I  did not try your suggestion and that was the one I needed!!!
THANK YOU

so now here is what I do:

1. first size each column to fit the data (width = -1) (Note: width =
-2 sizes the column to the header, so actually I get the header width
first and then use the larger of the two widths).

2. Set the listview width to be the sum of all the column widths + 2
times the Border3DSize + the width of a vertical scrow bar (Note, if
you do not include the width of the vertical scrow bar the
LVM_GETCOUNTPERPAG message will return a count which allows for a
horizontal scroll bar.)

3. Read the number of items that will fit using the
LVM_GETCOUNTPERPAGE message.

4. If the number of actual items is less than the number items that
will fit, I reset the listview width to not include the width of a
vertical scroll bar since there will not be one there.

This works like a champ. I have to admit, I usually stear away from
API calls but this works great. Are there any downsides to using it?

Thanks again Jason!! Great suggestion.

John

On Thu, 14 Apr 2005 14:38:11 -0500, Jason Newell <nospam@xxxxxxxxxx>
wrote:


JL,
Just curiuos, did sending the LVM_GETCOUNTPERPAGE meesage work for you? The LVM_GETCOUNTPERPAGE will tell you how man ListViewItems can be displayed before the scrollbar appears.


MSDN Quote: "LVM_GETCOUNTPERPAGE calculates the number of items that can fit vertically in the visible area of a list-view control when in list or report view. Only fully visible items are counted."

Just curious.

Jason Newell, MCAD
Software Engineer

J L wrote:

For those interested in this thread, here is what I have found that
seems to work:

Dim r As Rectangle = theListView.Items(0).Bounds
Dim htItems As Integer
' get whole number of items that will fit
' in the listview
htItems = theListView.Height/r.Height
' allow for column headers...not sure why 2 instead of 1
If htItems < theListView.Items.Count + 2
theListView.Width = sumOfColumnWidths + _
(SystemInformation.Border3DSize.Width * 2) + _
SystemInformation.VerticalScrollBarWidth
Else
theListView.Width = sumOfColumnWidths + _
(SystemInformation.Border3DSize.Width * 2) End If


This does fail on the condition that the last row that fills the list
view only partially fits. It puts the vertical scrow bar in the
listview but does not increase the size. I can write code to size th e
list view to an exact row count but if this is called repeatedly, I
loose track of the initial design height...does that make any sense to
any one...the code to size it to a whole number of rows is to add
before the If...End If clause:

theListView.Height = (htItems + 1) * r.Height

(i.e. use the number of items and the height of each, allow for the
headers)


If anyone has a comment, sees an error or knows a better approach, I would appreciate your inputs.

TIA,
John

On Wed, 13 Apr 2005 10:47:50 -0700, J L <ystem> wrote:



When I fill a listview, I resize the columns to fit the data. I need
to know if the data will fit vertically or if there will be a vertical
scroll bar. I need to know this so I can allow for it on the overall
size of the listview.

My question therefore is, how can I tell if the items I have added
will fit in the listview at its given height?

A secondary one, just for interest sake...is there a way to determine
the exact heght needed to hold the items?

TIA,
John



.



Relevant Pages

  • Re: Listview size
    ... Set the listview width to be the sum of all the column widths + 2 ... Read the number of items that will fit using the ... Thanks again Jason!! ... It puts the vertical scrow bar in the ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Listview size
    ... Dim htItems As Integer ... listview but does not increase the size. ... John ... I resize the columns to fit the data. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Listview size
    ... Dim fmt As StringFormat = New StringFormat ... This will return the height required for myText to fit into the listview ... you'll have to use windows api to achieve what ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Listview size
    ... The LVM_GETCOUNTPERPAGE will tell you how man ListViewItems can be displayed before the scrollbar appears. ... "LVM_GETCOUNTPERPAGE calculates the number of items that can fit vertically in the visible area of a list-view control when in list ... listview but does not increase the size. ... TIA, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Listviw SHOWSELALWAYS
    ... You are *really* trying to do much with the API when it's not necessary. ... Use the API to do things that the control doesn't ... SelectedItem property to Nothing. ... Perhaps you should spend more time reading MSDN Library on the ListView ...
    (microsoft.public.vb.controls)