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

Width of GridDropDownColumn and other columns in Edit Mode

3 Answers 280 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Boyan
Top achievements
Rank 1
Boyan asked on 02 Nov 2011, 12:56 AM
Hi, I wanted to get some suggestions as to what the easiest way to set or change grid column widths in edit mode. I have a grid that contains about 13 columns and when a row is in inline edit mode almost all columns become much wider which causes the grid to span more than the width of the screen which looks quite unpleasant. I have noticed that the grid drop-down columns become significantly wider than when not in edit mode.

I have played around with the different column resize options as mentioned here http://demos.telerik.com/aspnet-ajax/grid/examples/client/resizing/defaultcs.aspx
but I either find myself in a situation where column values are clipped or where the columns become too wide in edit mode.

Is it possible to changed the width of the text boxes in edit mode? And if yes, is the only solution to my problem to try to programmatically set the width of each textbox separately in the code-behind?

Many thanks in advance for your suggestions.

 

3 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 02 Nov 2011, 05:56 AM
Hello Boyan,

Try the following code snippet in ItemDataBound event to set width for columns in edit mode.
C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
   if (e.Item is GridEditableItem && (e.Item as GridEditableItem).IsInEditMode)
   {
     GridEditableItem edititem = e.Item as GridEditableItem;
     DropDownList ddl = (DropDownList)edititem["GridDropDownColumn"].Controls[0];//accessing GridDropDownColumn
     ddl.Width = Unit.Pixel(20);
   }
   if (e.Item is GridEditableItem && (e.Item as GridEditableItem).IsInEditMode)
   {
      GridEditableItem item = e.Item as GridEditableItem;
      TextBox txt = (TextBox)item["ColumnUniqueName"].Controls[0];//accessing GridBoundColumn
      txt.Width = Unit.Pixel(20);
   }
}

Thanks,
Shinu.
0
Boyan
Top achievements
Rank 1
answered on 31 Jan 2012, 08:22 PM
Thank you very much for the help, Shinu!

Just FYI, casting to TextBox worked fine, but casting to DropDownList did not.

In my case I had to use

((TextBox)editedItem["Column1"].Controls[0]).Width = Unit.Pixel(20);
((RadComboBox)editedItem["Column2"].Controls[0]).Width = Unit.Pixel(20);
((RadDatePicker)editedItem["Column3"].Controls[0]).Width = Unit.Pixel(20);

in other words, I had to cast the drop-down columns to RadComboBox and the date pickers to RadDatePicker.
0
Shinu
Top achievements
Rank 2
answered on 01 Feb 2012, 05:07 AM
Hello Boyan,

Try casting the DropDownColumn as RadComboBox.
C#:
RadComboBox combo = (RadComboBox)item["UniqueName"].Controls[0];

-Shinu.
Tags
Grid
Asked by
Boyan
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Boyan
Top achievements
Rank 1
Share this question
or