This is a migrated thread and some comments may be shown as answers.

[Solved] Column Widths

2 Answers 121 Views
Grid for XAML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
D
Top achievements
Rank 1
D asked on 01 Sep 2013, 11:06 AM
Hi,

I am having a few issues with column widths.I have three columns, one and two are SizeMode="Auto" and column three is SizeMode="Stretch".

Issue 1:
When the grid is resized, Column 3 does not resize to fill the available space. I have worked around this by changing the SizeMode of Column 3 to "Fixed" and putting in a SizeChanged event handler like this:

private void DataGrid_OnSizeChanged(object sender, SizeChangedEventArgs e)
{
    const int magicNumber = 30;
    var newWidth = e.NewSize.Width - DataGrid.Columns[0].ActualWidth - DataGrid.Columns[1].ActualWidth - magicNumber;
    newWidth = Math.Max(200, newWidth);
    DataGrid.Columns[2].Width = newWidth;
}

Is there a better way?

Issue 2:
If I change the content of Column 1 or 2 so that the Column becomes wider, how do I respond to that event so that I can recalculate the width of Column 3?

Issue 3:
If I change the content of Column 1 or 2 so that the content is narrower, the Column width does not shrink and instead there is blank space. How do I fix this? The columns can grow, but they never shrink.

Thanks,
Dunc

2 Answers, 1 is accepted

Sort by
0
Rosy Topchiyska
Telerik team
answered on 03 Sep 2013, 02:22 PM
Hi Dunc,

Thank you for using RadControls for Windows 8!

Directly to the issues you experience:

  • Issue 1: We could not reproduce this issue. I have attached a runnable sample application that has a RadDataGrid with three columns customized according to your setup. A RadNumericBox is used to control the width of the grid, and when you change it, the third column always takes the whole remaining space.
  • Issue 2,3: I have redirected this issue to our development team and they will do their best to fix it for the next official release Q3 2013 planned for mid-October.

    Until then, as a work-around I suggest you change the SizeMode of the columns to some other value and then set it back to its original value. Thus it will recalculate its size according to the current values in that column. I have implemented this in the sample application using the DataBindingComplete event of the RadDataGrid, as it is raised every time the ItemsSource is changed. 
You can also see that the width of the last column is always resized to fit the available space. If this issue is still present at your side, could you please modify the example project in order to reproduce it.

I also noticed that you are not using the latest version of the controls. I encourage you to update to the latest internal build (2013.2 806). You can get it using the Telerik Visual Studio Extensions or from this link when you are logged in on the site: http://www.telerik.com/account/your-products/internal-builds.aspx

I hope this was useful and, please, let us know if you need further assistance.

Regards,
Rositsa Topchiyska
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
D
Top achievements
Rank 1
answered on 05 Sep 2013, 08:23 PM
Hi Rositsa,

Thanks for the speedy reply! I have resolved all the issues now. The SizeMode="Stretch" thing was my own error, I had a custom control in that column and it had some wierd resizing logic that I needed to fix.

Your workaround of changing the SizeMode of the auto-width columns to some other value and then back to Auto also did the trick. Interesting I only needed to do this for the first column and my other auto-width columns seemed to work correctly too.

Thanks,
Dunc

Tags
Grid for XAML
Asked by
D
Top achievements
Rank 1
Answers by
Rosy Topchiyska
Telerik team
D
Top achievements
Rank 1
Share this question
or