DataGrid - Column resize event?

Feb 20, 2009 at 2:36 PM
Is there a event for when the user resizes a colum?

Because i have a textbox just under the datagrid that needs to be the same size as the datagrid at all time.

Or is there another way to get the same size on them?


// Jach
Feb 20, 2009 at 2:47 PM
I would imagine that you could data bind the TextBox's Width property to the ActualWidth property of a member of DataGrid.Columns, by name or by index (I prefer binding to elements by name). Something like this (written in web browser, and untested, but you get the idea):

<tk:DataGrid>
  <tk:DataGrid.Columns>
    <tk:DataGridTextColumn x:Name="something" Binding="{Binding Path}" />
  </tk:DataGrid.Columns>
</tk:DataGrid>
<TextBox Width="{Binding ElementName=something, Property=ActualWidth, Mode=OneWay}" Text="This text box should autosize" />
Feb 23, 2009 at 2:44 PM
Thanks i got it working with this:

<TextBox Width="{Binding ElementName='testColumn', Path='Width.DisplayValue', Mode=OneWay}" />

// JACH
Jul 24, 2009 at 7:38 PM

Is there a column resize event in the June 2009 release? I save column widths to the DB as user preferences, so I need to know when they resize columns. I can use the binding approach to capture updates, but if there's an event I can hook into, I'd rather use that. Thanks.

Jul 29, 2009 at 6:35 PM

bump? any workarounds for this?

Aug 5, 2009 at 2:51 AM

You could consider saving the preferences using an approach Vince outlined here:

http://www.codeproject.com/KB/WPF/WPF_Control_State_Persist.aspx

I'm assuming that you don't want to write the prefernces realtime (on resize event) but on window or "form" close.

Tracy

 

Mar 7, 2011 at 2:38 AM

I have a similar need to hook into the column resize event. in my case the width of the column is related to the value of the cell.

so if the value of the cell changes, then the column will need to resize as well, if the column width gets changed, the cell value needs to update.

any ideas on how to do this without an on resize event?

 

thanks,

David