Solved

Trouble fitting columns into a ListView

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

759 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now