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

Strange behavior of GridDateTimeColumnEditor : Textbox width

2 Answers 121 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Osman
Top achievements
Rank 1
Osman asked on 05 Mar 2009, 04:45 PM
Hi all,

I create a column of type GridDateTimeColumn dynamically and  add to my grid.

When I go in Edit mode, the width of the textbox control is too wide (default size) as I display and user only short dates(dd/mm/yyyy)...

In order to resize the control I subscribe to the CreateColumnEditor event on radgrid and change the TextBoxStyle.Width, at this moment the textbox control has a strange behavior ... In facts, it seems that the radgrid resize automatically the width of the textbox control to the width of the text...

        private static void CreateColumnEditorEventHandler(object sender, GridCreateColumnEditorEventArgs e)  
        {  
            if (e.ColumnEditor is GridDateTimeColumnEditor)  
            {  
                ((GridDateTimeColumnEditor)e.ColumnEditor).TextBoxStyle.Width = Unit.Pixel(50);  
            }    
        } 

Does anyone have an idea?

Thanks

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 06 Mar 2009, 10:26 AM
Hi Osman,

I tried the above code on my end and it is working as expected. One another suggestion will be to set width of the DatePicker in the ItemDataBound event when the Grid is in edit mode. Just give a try with the following code snippet and see if it works.

ASPX:
 
 
<telerik:GridDateTimeColumn  UniqueName="StartDate"    DataField="StartDate" HeaderText="StartDate"  ></telerik:GridDateTimeColumn> 

CS:
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        
        if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode)) 
        { 
            GridEditableItem edititem = (GridEditableItem)e.Item; 
            RadDatePicker dtpkr = (RadDatePicker)edititem["StartDate"].Controls[0]; 
            dtpkr.Width = Unit.Pixel(50); 
 
        
        }   
 
    } 

Thanks
Princy



0
Osman
Top achievements
Rank 1
answered on 06 Mar 2009, 10:36 AM
Hi Princy,

Thank you for your message. I tried your suggestion and it works fine.

Thanks again
Osman
Tags
Grid
Asked by
Osman
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Osman
Top achievements
Rank 1
Share this question
or