Hello,
I have a listview with two columns (the main listviewitem and one subitem), configured as a Detail View.
I have AutoFitColumns = ResizeallColumns.
The listview is anchored to a resizable form.
When I resize the form I want the first column (the MainColumn) to keep a constant widht. The second column should resize to take all the space available due to resizing.
Is there a way to get such behavior?
Thanks
Hello Brian.
I'm doing what you suggested and it solved the problem. After the listview is initialized in the form, i do this to set a fixed width:
myListView.MainColumn.PerformAutoResize();
myListView.MainColumn.Width = currentWidth;
Sorry, the sample I was using had some other code in it, and that other code was necessary to make this work. It took me a while to track it down, but I was calling the PerformAutoResize method on the MainColumn in my sample. That affects this scenario in an indirect way - when a column is auto-sized, we earmark it as, "don't change this column's width when auto-fitting the columns", based on the premise that since the user sized it explicitly, they would prefer it to stay that size. The last column to be auto-sized maintains its explicit width when possible, which is why PerformAutoResize made this work.
So in short, call PerformAutoResize on the MainColumn, and if you want to override that width, set it right after that. Please repost if you have any other problems with this.
Thanks for your answer Brian.
I configured a listview with those settings and I didn't get the desired behavior. I'm using version 2008 vol 2. Maybe it works fine on 2008 vol 3?
I'm attaching a test project. If you run it and resize the form the main column doesn't keep a fixed width.
If you set the MainColumn's width explicitly, it will stay that way (provided there is enough space) unless some other columns; width is set explicitly. I was able to get the behavior you described here using the following code:
this.ultraListView1.ViewSettingsDetails.AutoFitColumns = AutoFitColumns.ResizeAllColumns;this.ultraListView1.MainColumn.AllowSizing = DefaultableBoolean.False;this.ultraListView1.MainColumn.Width = 150;