?
Solved

Trouble fitting columns into a ListView

Posted on 2006-06-16
5
Medium Priority
?
244 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month9 days, 7 hours left to enroll

762 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