Solved

Trouble fitting columns into a ListView

Posted on 2006-06-16
5
236 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

808 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