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

Column width binding

4 Answers 427 Views
GridView
This is a migrated thread and some comments may be shown as answers.
JP
Top achievements
Rank 1
JP asked on 25 Mar 2009, 04:02 PM
Hello,

I believe I've run into another breaking change with the Q1 2009 version of the grid.  In my app I have some functionality where the user can define some of the properties of a grid, one of them being the column widths.  When the user is looking at some data in the grid and they resize a column I need to update by business object so that I can display the grid with the same widths the next time.

In the previous version I accomplished this by having a two way binding between the Width property of a grid column and a width property on my business object (using a converter to translate back and forth between a numeric value and a GridLength).  This worked perfectly as every time the user changed a column width my object was updated. 

In the Q109 version, resizing a column doesn't seem to update the column width anymore so my object never gets updated.  The only time the width gets updated is when you double click in the header to make the column fit the contents.  This also has the unfortunate side effect of setting the column with to Auto and the value to 1, which is not desired.  I would expect that the column would be resized, but the mode stay in Pixel mode like it used to.

Is there any way to get the grid to behave like it used to?  If not, can someone please suggest a way for me to know when a column gets resized and then get the actual width of the column?  I had a similar post a while back but that method doesn't seem to work anymore either.

Thanks,

Joel

4 Answers, 1 is accepted

Sort by
0
Accepted
Stefan Dobrev
Telerik team
answered on 26 Mar 2009, 12:03 PM
Hello Joel,

We have done a major refactoring of column resizing logic for Q1. As part of this effort we have broken some things that used to work before - as in your case when the width is not updated correctly. We will try to address this for our service pack release.

Meanwhile I have prepared a sample application that illustrates what you are trying to achieve. It uses an internal property of GridViewColumn - PixelWidth that we are using in our internal layout infrastructure. The sample also exposes some attached behaviors that allow codeless (pure XAML) data binding to this property.

Hope this helps.

Sincerely yours,
Stefan Dobrev
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
JP
Top achievements
Rank 1
answered on 26 Mar 2009, 05:35 PM
Hi Stefan,

Thank you very much for the sample project.  It was a great help in finding a solution to my problem, though I didn't use all of it.  My real goal was just to somehow know when the column width was updated and how to get the width of the column and using your example I figured out how to do that.  What I ended up doing was just handling the column's property changed event and looking for the PixelWidth property.  I then used reflection to get at the value.  Below is part of my code:

// In some other method 
column.PropertyChanged += new PropertyChangedEventHandler(Column_PropertyChanged); 
 
        void Column_PropertyChanged(object sender, PropertyChangedEventArgs e) 
        { 
            if (e.PropertyName == "PixelWidth"
            { 
                var pixelWidthProperty = typeof(GridViewColumn).GetProperty("PixelWidth", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); 
                var value = pixelWidthProperty.GetValue(sender, null); 
                var field = ((GridViewDataColumn)sender).Tag as ColumnSettings; 
                field.Width = Convert.ToInt32((double)value); 
            } 
        } 

I would much rather just bind to the width property like I used to though, so I hope that this bug gets fixed in the next service pack.

Thanks,

Joel
0
haagel
Top achievements
Rank 1
answered on 09 Jun 2010, 01:51 PM
I also want to have a two way binding between the widths of my columns and properties (in my ViewModel). Is this issue fixed by now or must I still use the "fix"?
0
Yavor Georgiev
Telerik team
answered on 10 Jun 2010, 09:50 AM
Hello David Haglund,

 Please find attached a sample solution that demonstrates how to bind the Width of a column to a property on your ViewModel.

Greetings,
Yavor Georgiev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
JP
Top achievements
Rank 1
Answers by
Stefan Dobrev
Telerik team
JP
Top achievements
Rank 1
haagel
Top achievements
Rank 1
Yavor Georgiev
Telerik team
Share this question
or