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

Change GridDropDownColumn width during edit mode in detail table?

4 Answers 254 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 21 Jul 2010, 04:58 PM
Hi,

I am trying to change the width of a GridDropDownColumn in a detail table during editmode so the items do not wrap to more than one line just something simple like 500px. Nothing seems to work. I have tried accessing the control in itemdatabound event but cannot seem to get this working for detail tables, even though I have it working fine when there are no details tables.

Any help much appreciated.

Thanks,
Paul

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 22 Jul 2010, 06:37 AM
Hellp Paul,

In ItemDataBound check for the name of DetailTable to access the control in DropDownColumn of that table.

ASPX:
<telerik:RadGrid ID="RadGrid2" DataSourceID="SqlDataSource1" runat="server" OnItemDataBound="RadGrid1_ItemDataBound">
 <MasterTableView Name="Master" runat="server" EditMode="InPlace">
   <DetailTables>
     <telerik:GridTableView Name="GridTableView1" runat="server" DataSourceID="SqlDataSource2"
                EditMode="InPlace">
         <Columns>
            <telerik:GridDropDownColumn UniqueName="GridDropDownColumn" DropDownControlType="DropDownList">
            </telerik:GridDropDownColumn>
            <telerik:GridEditCommandColumn>
            </telerik:GridEditCommandColumn>
         </Columns>
     </telerik:GridTableView>
   </DetailTables>
 </MasterTableView>
</telerik:RadGrid>

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditableItem && e.Item.IsInEditMode && e.Item.OwnerTableView.Name == "GridTableView1")//check with the name of DetailTable
        {
            GridEditableItem editItem = (GridEditableItem)e.Item;
            DropDownList drList = (DropDownList)editItem["GridDropDownColumn"].Controls[0];
            drList.Width = Unit.Pixel(500);
        }
    }

Hope this helps,
Princy.
0
Paul
Top achievements
Rank 1
answered on 22 Jul 2010, 04:26 PM
Hi Princy

I am using form edit mode and pretty much same code as you but no joy.  Here is what I am doing.  I set a breakpoint in the section where it should change the width but it never gets there.

protected void RadGridShifts_ItemDataBound(object sender, GridItemEventArgs e)
        {
            try
            {
                // Perform default value settings
                if (e.Item.OwnerTableView.IsItemInserted && e.Item is GridEditFormInsertItem)
                {
                    // Auto complete when the shift was created
                    GridEditFormInsertItem item = (GridEditFormInsertItem)e.Item;
                    TextBox textBox = (TextBox)item["Shift_Created_Date"].Controls[0];
                    textBox.Text = DateTime.UtcNow.ToString();
                }
 
                // Item about to be edited
                if (!(e.Item is GridDataInsertItem) && e.Item.IsInEditMode)
                {
                    RadDateTimePicker DeadlineRadDatePicker = (RadDateTimePicker)e.Item.FindControl("Shift_DeadlineRadDatePicker");
                    DeadlineRadDatePicker.MinDate = DateTime.Now.Date;
                }
 
// TRIED GridEditableItem here too and neither ever enters if statement
                if (e.Item is GridEditFormItem && e.Item.IsInEditMode && e.Item.OwnerTableView.Name == "GridTableViewLocations")
                {
                    GridEditableItem editItem = (GridEditableItem)e.Item;
                    DropDownList ddl = (DropDownList)editItem["LocationLookup"].Controls[0];
                    ddl.Width = Unit.Pixel(500);
                }
 
                // Control whether edit button should be enabled
                if (e.Item is GridDataItem)
                {
                    GridDataItem item = (GridDataItem)e.Item;
                    Button btnEdit = (Button)item["EditButton"].Controls[0];
                    DateTime? dateDeadline = DateTime.Parse(((DataRowView)e.Item.DataItem)["Shift_Deadline"].ToString());
 
                    if (btnEdit != null && dateDeadline.HasValue)
                        if (dateDeadline < DateTime.UtcNow) btnEdit.Enabled = false;
                }
            }
            catch (Exception ex)
            {
            }
        }


<DetailTables>
                <telerik:GridTableView runat="server" DataSourceID="ObjectDataShiftLocations" DataKeyNames="Shift_Id"
                    ShowFooter="false" CommandItemDisplay="Top" CommandItemSettings-AddNewRecordText="Add New Location To Shift"
                    AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True"
                    OnNeedDataSource="RadGridLocation_NeedDataSource" Name="GridTableViewLocations">
                    <PagerStyle AlwaysVisible="false" />
                    <ParentTableRelation>
                        <telerik:GridRelationFields DetailKeyField="Shift_Id" MasterKeyField="Id" />
                    </ParentTableRelation>
                    <CommandItemSettings AddNewRecordText="Add New Location To Shift"></CommandItemSettings>
                    <Columns>
                        <telerik:GridButtonColumn CommandName="Edit" Text="Edit" UniqueName="commandEdit"
                            ButtonType="ImageButton">
                            <ItemStyle HorizontalAlign="Center" Width="30px"></ItemStyle>
                        </telerik:GridButtonColumn>
                        <telerik:GridButtonColumn CommandName="Delete" Text="Remove" UniqueName="commandDelete"
                            ButtonType="ImageButton">
                            <ItemStyle HorizontalAlign="Center" Width="30px"></ItemStyle>
                        </telerik:GridButtonColumn>
                        <telerik:GridDropDownColumn UniqueName="LocationLookup" DataSourceID="ObjectDataSourceLocationLookup"
                            DataField="Location_Id" ListValueField="Location_Id" ListTextField="Short_Name"
                            DropDownControlType="RadComboBox" HeaderText="Location To Check">
                        </telerik:GridDropDownColumn>
                    </Columns>
                    <EditFormSettings>
                        <EditColumn UniqueName="EditCommandColumnLocationCheck" ButtonType="ImageButton">
                        </EditColumn>
                    </EditFormSettings>
                </telerik:GridTableView>
            </DetailTables>


This is really driving me nuts.  Can you see something really simple I am missing as its so obvious I just cannot spot it?

Thanks
0
Accepted
Princy
Top achievements
Rank 2
answered on 23 Jul 2010, 01:20 PM
Hello Paul,

Since you are setting DropDownControlType property of GridDropDownColumn as 'RadComboBox', access the control as RadComboBox and see whether this solves your issue.


C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
   {
    if (e.Item is GridEditFormItem && e.Item.IsInEditMode && e.Item.OwnerTableView.Name == "GridTableViewLocations")
        {
          GridEditableItem editItem = (GridEditableItem)e.Item;
          RadComboBox combo= (RadComboBox)editItem["LocationLookup"].Controls[0];
          combo.Width = Unit.Pixel(500);
        }
   }

Thanks,
Princy.
0
Paul
Top achievements
Rank 1
answered on 23 Jul 2010, 02:28 PM
Many thanks Princy.  The Master strikes again
Tags
Grid
Asked by
Paul
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Paul
Top achievements
Rank 1
Share this question
or