Solved

Trouble fitting columns into a ListView

Posted on 2006-06-16
5
237 Views
Last Modified: 2010-04-16
Hi,

I add columns to the ListView thusly:

driverLV.Columns.Add("Driver",            105,      HorizontalAlignment.Left);
driverLV.Columns.Add("# Runs",            50,      HorizontalAlignment.Left);
driverLV.Columns.Add("# Orders",      55,      HorizontalAlignment.Left);

It all works okay, but I need to fuss endlessly to get the columns to fit into the space provided by the size of the ListView.  Is there an easier way?  For example, is there a way I could specify the width of th first two, then use all remaining space for the final column.  But not so much that it would add a scroll bar?


Thanks,
Bob
0
Comment
Question by:ba272
  • 3
  • 2
5 Comments
 
LVL 18

Accepted Solution

by:
Ravi Singh earned 500 total points
ID: 16926340
Hi, I don't think theres an easy way around this with the standard ListView, you can set the width of each column to -2 when there are items in the control, that should autosize the last column, but if the user resizes the first two columns then the last column is not auto-resized. The best way to resolve it is to create a subclass of the ListView control and override the WndProc method so that the last column always expands itself to the end of the ListView's width (similar solution to the above), the code that needs to go in the WndProc is given in the article below:

http://www.codeproject.com/cs/miscctrl/listviewautosize.asp
0
 

Author Comment

by:ba272
ID: 16927013
I have created a subclass to ListView, as the article described.  But when it comes to using it, I'm at a bit of a loss.  Normally, I use the designer to create my controls.  Will I need to create the new ListView dynamically?
0
 

Author Comment

by:ba272
ID: 16927021
It would be real cool if I could design my dialogs using a standard ListView.  Then in the _Load function replace any ListView with MyListView, using the same parameters set as properties for the ListView.

I think this would mostly mean reading the X,Y coordinates of the ListView, then deleting it.  Next, create a MyListView with the same coordinates.  Does this make sense?

Thanks,
Bob
0
 

Author Comment

by:ba272
ID: 16927051
scratch that.  It's working great.

Thanks.
0
 
LVL 18

Expert Comment

by:Ravi Singh
ID: 16927197
Hi Bob, sorry I was away for a while - glad you got it working, if you have any further problems let us know.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used.

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question