Welcome to the Xceed Community | Help
Community Search  
More Search Options

Column auto-sizing according to the host control size

Sort Posts: Previous Next
  •  04-22-2008, 6:44 AM Post no. 11642

    Column auto-sizing according to the host control size

    I'm trying to have in my data grid control columns which will change their width respectively to the actual  width of the data grid control (which host them). At the moment I'm creating the columns in code-behind, and setting up a binding on the Column WidthProperty using converter (with number of columns as ConverterParameter). Performances are not so good, that is why I'm looking for something else in order to solve this request. 

    Is there any solution for getting auto sizing of column (width of the column) in a data grid control respectively to the width of the column host control (i.e. - the "actual width" of the DataGrid control)? 

    p.s. - I"m using XceedDataGridControl v.2

  •  04-22-2008, 10:14 AM Post no. 11646 in reply to 11642

    Re: Column auto-sizing according to the host control size

    Column Auto-Sizing is not supported in version 2.0 of the DataGrid for WPF.

    Support for Column Auto-Sizing is currently planned for version 2.1.

    For more details on version 2.1, please refer to the roadmap, which can be found here:
    http://xceed.com/CS/forums/thread/11207.aspx

    Marc Laroche
    Software Developer
    Xceed Software Inc.


    I don’t suffer from insanity, I enjoy every minute of it. - Unknown
    Filed under:
  •  07-29-2008, 7:33 PM Post no. 13791 in reply to 11646

    Re: Column auto-sizing according to the host control size

    Hello

    I created a control that is very similar to http://xceed.com/CS/forums/thread/8224.aspx.
    The 1st version of the control worked for pages with no hidden grids, but when these became visible not worked. (bad for me :()
    this custom version works with all grids of the page, and when they become visible automatically adjust the columns (the trick is in the loaded because GetFittedWidth always return a valid value)

     

    Any sugestions email-me

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Xceed.Wpf.DataGrid;
    using System.Windows.Controls;
    using System.Collections;


    namespace etcetcetc.Grid
    {
    public class ctrGrid : Xceed.Wpf.DataGrid.DataGridControl
    {
    private bool RunAutoFit = false;
    public ctrGrid()
    : base()
    {
    this.Loaded += new System.Windows.RoutedEventHandler(ctrGrid_Loaded);

    this.LayoutUpdated += new EventHandler(Grid_LayoutUpdated);
    }

    void ctrGrid_Loaded(object sender, System.Windows.RoutedEventArgs e)
    {
    this.RunAutoFit = true;
    Grid_LayoutUpdated(null, null);
    }


    private void Grid_LayoutUpdated(object sender, EventArgs e)
    {
    if (this.RunAutoFit && this.IsVisible)
    {
    AutoFit();
    this.RunAutoFit = false;
    }
    }

    public void AutoFit()
    {
    foreach (Column col in this.Columns)
    {
    double fittedWidth = col.GetFittedWidth();

    if (fittedWidth > 0)
    col.Width = fittedWidth + 2;
    }
    }

    protected override void OnItemsSourceChanged(System.Collections.IEnumerable oldValue, System.Collections.IEnumerable newValue)
    {
    UpdateLayout();
    base.OnItemsSourceChanged(oldValue, newValue);

    this.RunAutoFit = true;
    }
    }
    }
  •  11-17-2008, 3:10 PM Post no. 16945 in reply to 11642

    Re: Column auto-sizing according to the host control size

    As a precision this feature (column stretching and starrable column widths) was introduced in version 3.0.


    Vince
    Developer
    Xceed Software Inc.
  •  03-12-2009, 9:57 PM Post no. 19258 in reply to 16945

    Re: Column auto-sizing according to the host control size

    That's nice. But how does one do it? 

     In my case I have a particular grid that has dynamic columns, so I can't specify the columns or widths.

     What I would really like is the column to shrink to whatever is biggest, the column header name or the content.

  •  03-18-2009, 1:35 AM Post no. 19367 in reply to 19258

    Re: Column auto-sizing according to the host control size

    Ross:

    That's nice. But how does one do it? 

    +1 ... Why is it so hard to find information on auto-sizing columns?

  •  04-03-2009, 9:47 AM Post no. 19916 in reply to 19367

    Re: Column auto-sizing according to the host control size

    I am also loading Tables into the Grid dynamically.  Was there a way to have the column autosize depending on the data that is in the Grid?  (I would also like the Columns to autosize to the largest cell even if its not in the viewport.
  •  01-26-2010, 9:27 AM Post no. 25548 in reply to 19916

    Re: Column auto-sizing according to the host control size

    I made a small modification to this class that might help some users experiencing similar problems to me:

    http://www3.xceed.com/CS/forums/permalink/25546/25546/ShowThread.aspx#25546


    Associate, .NET Development
    Morgan Stanley, UK
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.