Posted 21 October 2021, 5:13 am EST
Hi,
I’ve got your point. Actually, this is the design behavior of Auto Width column, if cell content size increase, then column width will also increases. At the time of editing the cell content size is increasing that’s why Width of column is increasing as well.
However, you can do a workaround. You need to keep column width at the time of editing start and then you can set same width again when Editor load.
private void Began_Edit(object sender, C1.WPF.DataGrid.DataGridBeganEditEventArgs e)
{
if(e.EditingElement is C1DateTimePicker)
{
var editor = e.EditingElement as C1DateTimePicker;
var width = e.Column.ActualWidth;
editor.Loaded += new RoutedEventHandler((s, e2) => Editor_Loaded(s, e2, e.Column.Index,width));
}
}
private void Editor_Loaded(object sender, RoutedEventArgs e,int index,double width)
{
var dtPicker =sender as C1DateTimePicker;
var timeEditor =dtPicker.Template.FindName("TimeEditor",dtPicker) as C1TimeEditor;
var txtBox =timeEditor.Template.FindName("TextBox",timeEditor) as C1MaskedTextBox;
txtBox.ReplaceMode = true;
timeEditor.CustomFormat = "HH:mm";
timeEditor.Mask = "00:00";
timeEditor.ShowButtons = false;
grid.Columns[index].Width = new C1.WPF.DataGrid.DataGridLength(width);
}
*Note:- Auto value will be lost from Column Width property.
Please refer the attached modified sample for the same : DataGridDateTimeColumn_Mod3.zip
Regards,
Nitin