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

double click column header gridsplitter to automatically adjust the size

5 Answers 316 Views
GridView
This is a migrated thread and some comments may be shown as answers.
mirang
Top achievements
Rank 1
mirang asked on 04 Oct 2011, 05:41 AM
I there any way we can automatically adjust the column width when the user double clicks on the splitter in column. Currently the user has to select the splitter and drag in order to size it.

5 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 04 Oct 2011, 06:35 AM
Hello,

 We believe that this is supported by default. You can try for example resize/auto adjust on this demo:
http://demos.telerik.com/silverlight/#GridView/DomainDataSource

Best wishes,
Vlad
the Telerik team

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

0
mirang
Top achievements
Rank 1
answered on 04 Oct 2011, 07:35 AM
I am not able to do this when i set the column width in * say 10*, 20*... Can you please verify this  behavior.
0
mirang
Top achievements
Rank 1
answered on 04 Oct 2011, 07:41 AM
a sample code for the same : 
XAML : 
<UserControl xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"  x:Class="SilverlightApplication1.Grid.RadGridDemo1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
    
    <Grid x:Name="LayoutRoot" Background="White">
        <telerik:RadGridView x:Name="gridView" Grid.Row="1" IsReadOnly="True" AutoGenerateColumns="False" VerticalAlignment="Stretch"
                             SelectionUnit="FullRow" EnableRowVirtualization="True" EnableColumnVirtualization="True"
                             VerticalContentAlignment="Top" ItemsSource="{Binding Results}" AutoExpandGroups="True"
                             SelectedItem="{Binding SelectedItem, Mode=TwoWay}" CanUserFreezeColumns="False"
            telerik:AnimationManager.IsAnimationEnabled="False"
            AutomationProperties.AutomationId="OWS_Results_Mail_GridControl">
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding EmpID}" Width="30*" />
                <telerik:GridViewDataColumn DataMemberBinding="{Binding EmpLastName}" Width="30*"/>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding EmpDesig}"  Width="40*"/>
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
    </Grid>
</UserControl>


Code Behind : 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;


namespace SilverlightApplication1.Grid
{
    public class SampleDataSource
    {
        public int EmpID { get; set; }
        public string EmpLastName { get; set; }
        public string EmpDesig { get; set; }


    }
    public partial class RadGridDemo1 : UserControl
    {
        public List<SampleDataSource> sampleData;
        public RadGridDemo1()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(RadGridDemo1_Loaded);
        }


        void RadGridDemo1_Loaded(object sender, RoutedEventArgs e)
        {
            GenerateData();
            this.DataContext = sampleData;
            gridView.ItemsSource = sampleData;
        }
        private void GenerateData()
        {
            List<SampleDataSource> sd = new List<SampleDataSource>();
            for(int i = 0 ; i < 100 ; i++)
            {
                SampleDataSource sd1 = null;
                if(i % 3 ==0)
                {
                    sd1 = new SampleDataSource { EmpID = i, EmpDesig = "Senior Software Engineer", EmpLastName = "last name " + i };
                }
                else if (i % 2 == 0)
                {
                    sd1 = new SampleDataSource { EmpID = i, EmpDesig = "Engineer", EmpLastName = "last name " + i };
                }
                else if (i % 1 == 0)
                {
                    sd1 = new SampleDataSource { EmpID = i, EmpDesig = "Software Engineer", EmpLastName = "last name " + i };
                }
                sd.Add(sd1);
            }
            sampleData = sd;
        }
    }
}

0
Cody
Top achievements
Rank 1
answered on 07 Jun 2018, 10:37 PM
mirang is right, it seems that this doesn't work if the ColumnWidth is set to * rather than auto. I'm using WPF but the behavior seems to be the same. Is there no way to hook the divider double click event so that I can programmatically change the column width to Auto? Strange that this doesn't work by default.
0
Stefan
Telerik team
answered on 12 Jun 2018, 12:44 PM
Hello Cody,

You can use the ColumnWidthChanging event to achieve your goal. It will be raised when the user resizes a given column through the UI. Can you please check it out?

Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
GridView
Asked by
mirang
Top achievements
Rank 1
Answers by
Vlad
Telerik team
mirang
Top achievements
Rank 1
Cody
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or