How to set GridViewDataColumn width to Fill?

7 posts, 1 answers
  1. Tony
    Tony avatar
    21 posts
    Member since:
    Oct 2011

    Posted 07 Dec 2011 Link to this post

    Hi,

    I'm getting an extra column at the end of my grid when I resize the container. 

    Reading the posts, I note that one way that I should be able to remove this extra column is by setting the width of the last column to fill (i.e. "*").

    However, I am using an ObsevableCollection of GridViewDataColumns to generate the columns of my grid.

    How do I set the width of the a GridViewDataColumn to fill.  Width takes a value of type GridViewLength which only have 3 options (i.e. Auto, SizeToCells, SizeToHeader) of which the default is Auto.

    Thanks,

    Tony

  2. Answer
    Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 09 Dec 2011 Link to this post

    Hello Tony,

     You could set the width to "*" like so:

    column.Width = new GridViewLength(1, GridViewLengthUnitType.Star);

    Please let me know if this is what you need. 

    Greetings,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. Tony
    Tony avatar
    21 posts
    Member since:
    Oct 2011

    Posted 13 Dec 2011 Link to this post

    Thanks Didie - this worked like a charm.

    Regards,

    Tony
  5. Erlend
    Erlend avatar
    1 posts
    Member since:
    Aug 2014

    Posted 27 Aug 2014 Link to this post

    I had the same problem, and used Width as suggested above on Column:
    <telerik:GridViewDataColumn DataMemberBinding="{...}" Header="{...}" IsReadOnly="True" Width="*"/>

    But this causes strange behavior when the user drags to resize the column headers of other cells next to the stretched column. Any other way of achieving column stretch of a specific column without destroying column resize behaviour?
  6. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 28 Aug 2014 Link to this post

    Hello,

    Generally if you have a column with Width="*", then you should be able to still re-size any of the columns. Would you please share more details or a demo project on this strange behavior you experience?

    Regards,
    Didie
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  7. Bruno
    Bruno avatar
    3 posts
    Member since:
    Sep 2014

    Posted 18 Dec 2014 in reply to Dimitrina Link to this post

    Hello,

    I think we are experiencing the same stringe behavior as Erlend.
    It can be simulated with your WPF Controls Examples application: GridView Examples, Example 'Custom Sorting'.
    When there is a combination of columnwidth Auto and *, the resizing is strange:

    - Trying to make the columns City, Country or Phone larger fails and other columns collapse
    - Trying to extend the company name results into flickering

    We would like to have the following behavior:
    - If there are too many columns, a horizontal scrollbar should appear (this is probably not possible with star column width?)
    - When resizing, only the current column should resize
    - When there are few columns, they should stretch to fill the full grid width

    The closest I get is to set all column widths to auto, then the first 2 issues are handled.
    Is there a possibility to handle all issues?

  8. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 22 Dec 2014 Link to this post

    Hi,

    As it turns out I cannot suggest you a solution to achieve all three points. Currently, we have an issue logged into our system regarding:
    ​After column with width=* is resized to it's minimum width, it cannot be resized to a larger width.
    Still, this issue is still not resolved.

    Regards,
    Dimitrina
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
DevCraft banner