View previous topic :: View next topic |
Author |
Message |
taurin
Joined: 03 Jan 2008 Posts: 7
|
Posted: Fri Aug 14, 2009 6:22 pm Post subject: Problem with column resizing when made active |
|
|
Hi, I have 3 columns in my tree (A, B, and C). A always shows, but only one of the others shows at any given time. I have AutoFitColumns set to True.
Usually when I hide a column and show the other, they will show as the same size (which is what I want). However, if I auto-size the first column (by double clicking on the separator) and then hide/show the columns, the sizes will not stay the same (they will be different depending on which column is showing). I have tried storing the width of the columns before hiding and showing and then setting it afterward, but it ignores this change.
Is there anything I can do without losing the benefits of AutoFitColumns?
Last edited by taurin on Tue Aug 18, 2009 9:13 pm; edited 1 time in total |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Sat Aug 15, 2009 1:06 am Post subject: |
|
|
Thanks for posting the sample project - that certainly makes it easier to see what the issue is. Your tree has AutoFitColumns set to true which means that it will resize the columns to make them fit the available width for the tree control. It uses the Column.AutoFitWeight property to determine the relative proportion of the total width to assign to each column. The AutoFitWeight property is set by default to 1 for each column - which means that the columns are all of equal width. When the user resizes a column the AutoFitWeight is recalculated for each column so that if you resize the total control width the same proportions are maintained. So what is happening in your sample is that the AutoFitWeights of the active columns have been updated when the user resizes the first column - however the inactive column still has the original value of 1 for AutoFitWeight. When you make it active it therefore changes the layout. The solution is to set the AutoFitWeight of the column you are making active to the value of the now inactive column. Here is the code:
Code: | private void ShowColumns()
{
virtualTree1.SuspendLayout();
try
{
colFieldTwoData.Active = chkShowData.Checked;
colFieldTwoName.Active = !chkShowData.Checked;
if (colFieldTwoData.Active)
{
colFieldTwoData.AutoFitWeight = colFieldTwoName.AutoFitWeight;
}
else
{
colFieldTwoName.AutoFitWeight = colFieldTwoData.AutoFitWeight;
}
}
finally
{
virtualTree1.ResumeLayout();
}
} |
_________________ Infralution Support |
|
Back to top |
|
|
taurin
Joined: 03 Jan 2008 Posts: 7
|
Posted: Mon Aug 17, 2009 2:44 pm Post subject: |
|
|
Worked like a charm, thanks for the help. |
|
Back to top |
|
|
|