Is NTreeList BestFit asynchronous?


https://www.nevron.com/Forum/Topic9471.aspx
Print Topic | Close Window

By Craig Swearingen - 9 Years Ago
Using build 15.11.12.12 on Win7.  I'd like to use the NTreeList BestFit or BestFitAllColumns method to change my column widths based on the data in the NTreeList.  However, for a few columns I don't want their width to be greater than 200.  I'm calling:

myTree.BestFitAllColumns();
if (myTree.Columns["largetextcol"].Width > 200)
    myTree.Columns["largetextcol"].Width = 200;

The setting of 200 doesn't work.  The BestFitAllColumns width is used instead.  If I change it like this:

myTree.BestFitAllColumns();
myTree.Update();
if (myTree.Columns["largetextcol"].Width > 200)
    myTree.Columns["largetextcol"].Width = 200;


This works.  Unless my NTreeList is not visible.  In my case my NTreeList may be on a tab of a NTabControl that is not visible.  I've tried some other methods on the NTreeList widget but nothing seems to help.  How can I get the BestFitAllColumns algorithm to run such that I can then set my max column widths?
By Nevron Support - 9 Years Ago
Hello Craig,

You can try to change the column width when some of the column's property has changed by attaching to NTreeList.ColumnNotify event as follows:


myTree.ColumnNotify += nTreeList1_ColumnNotify;

...

void nTreeList1_ColumnNotify(object sender, NTreeListColumnNotifyData data)
{
    NTreeListColumn column = nTreeList1.Columns["largetextcol"];
    column.Header.Text = column.Width.ToString();

    if (data.Column == column
        && data.NotifyCode == NTreeList.ColumnPropertyChangedNotifyCode
        && column.Width > 200)
    {
        column.Width = 200;
    }
}


This way when the control becomes visible the event handler for ColumnNotify should be called and the column resized.

I hope this helps.
By Craig Swearingen - 9 Years Ago
Thanks for the tip.  I was wondering if I would need to approach it similarly but I was hoping I was just missing something that was available to do synchronously.