DataGrid.CanUserResizeColumns Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets a value that indicates whether the user can adjust column widths using the mouse.

Namespace:  System.Windows.Controls
Assembly:  System.Windows.Controls.Data (in System.Windows.Controls.Data.dll)

Syntax

'Declaration
Public Property CanUserResizeColumns As Boolean
public bool CanUserResizeColumns { get; set; }
<sdk:DataGrid CanUserResizeColumns="bool"/>

Property Value

Type: System.Boolean
true if the user can resize columns; otherwise, false. The default is true.

Remarks

Dependency property identifier field: CanUserResizeColumnsProperty

You can set this behavior for individual columns by setting the DataGridColumn.CanUserResize property. If the DataGridColumn.CanUserResize property and the DataGrid.CanUserResizeColumns property are both set, a value of false will take precedence over a value of true.

Examples

The following code example demonstrates how to set the CanUserResizeColumns property in code. This example is part of a larger example available in the Walkthrough: Customizing the DataGrid Control Using Properties topic.

Private Sub cbColResize_Changed(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
    Dim cb As CheckBox = sender
    If Me.dataGrid1 IsNot Nothing Then
        Me.dataGrid1.CanUserResizeColumns = cb.IsChecked
    End If
End Sub
private void cbColResize_Changed(object sender, RoutedEventArgs e)
{
    CheckBox cb = sender as CheckBox;
    if (this.dataGrid1 != null)
        this.dataGrid1.CanUserResizeColumns = (bool)cb.IsChecked;
}

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.