Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Trouble fitting columns into a ListView

Posted on 2006-06-16
5
Medium Priority
?
251 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 18

Accepted Solution

by:
Ravi Singh earned 2000 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

618 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