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

Change batchColumnEditor autogenerated to a dropdown or something else

3 Answers 102 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bouyez
Top achievements
Rank 1
Bouyez asked on 17 Jan 2017, 03:51 PM

Hi,

I need to change (c#) the default editor for a column (texdbox) to a dropdownlist or other when I autogenerate column. (depend on constraint->SQLConstraint.png)

OnNeedDataSource -> RadGridEdit.Source = a dataTable;

RadGridEdit_PreRender -> Display_mode_column(true);

foreach (GridColumn col in RadGridEdit.MasterTableView.AutoGeneratedColumns)
{

    [....]

    if((string)rows[0][4] == "DROPDOWN" && sender != null){
    foreach (GridDataItem dataItem in RadGridEdit.MasterTableView.Items)
    {

      DropDownList ddl = new DropDownList();
      ddl.ID = "DDL_" + col.UniqueName; 
      ddl.DataSource = dataDefinition.Tables[1];
      ddl.DataTextField = "ListValueLabel";
      ddl.DataValueField = "ListValueLabel";
      ddl.ControlStyle.Width = Unit.Percentage(100);
      ddl.DataBind();
      dataItem[col.UniqueName].Controls.Add(ddl);

     }

}

This don't work, I get my showed data with a dropDown and if I click on the row, I still got this TextBox in edit mode (BatchEditYoloMode.png).

So, How can I change this edit textbox into a dropdown (timepicker , ....). (GetBatchColumnEditor?)

3 Answers, 1 is accepted

Sort by
0
Bouyez
Top achievements
Rank 1
answered on 18 Jan 2017, 09:59 AM

I finally find a solution, 

http://www.telerik.com/forums/createcolumneditor-event-to-change-editor-control-type

But, must I create a custom control to all possibilities of edit type or can I easily change de columneditor type ?

Thx

0
Bouyez
Top achievements
Rank 1
answered on 28 Mar 2017, 01:32 PM

I try to update my version to 2017.1.128 but I got a good one:

(Batch Edit)

When I change value and click on save button, no problem, everything is good.

BUT, when I try to add a new row and click ob

at MyProject.GridEdit.CustomRadDropDownListEditor.get_Text() in d:\Users\jbo\Desktop\TFS\ReportViewerRve\ReportViewerRve\GridEdit.aspx.cs:line 1456
   at Telerik.Web.UI.GridBoundColumn.FillValues(IDictionary newValues, GridEditableItem editableItem)
   at Telerik.Web.UI.GridBatchEditingCommand.<FillEmptyOldValues>b__1(GridEditableItem dataItem)
   at Telerik.Web.UI.GridBatchEditingHelper.CreateFakeEditableItem(GridTableView tableView, Action`1 callback)
   at Telerik.Web.UI.GridBatchEditingCommand.FillEmptyOldValues()
   at Telerik.Web.UI.GridBatchEditingCommand..ctor(GridTableView ownerTableView, DataSourceView dataSourceView, String command)
   at Telerik.Web.UI.GridBatchEditingEventArgs.CreateCommands()
   at Telerik.Web.UI.GridBatchEditingEventArgs.get_Commands()

 

Here is the code of my CustomDropdownEditor:

public class CustomRadDropDownListEditor : GridTextColumnEditor
        {
            private RadDropDownList _ddl;
            private DataTable _dt;
            private string _version;
 
            public CustomRadDropDownListEditor(DataTable dt, string version)
            {
                this._dt = dt;
                this._version = version;
            }
 
            protected override void LoadControlsFromContainer()
            {
                this._ddl = this.ContainerControl.Controls[0] as RadDropDownList;
                //this._ddl = this.ContainerControl.Controls[0] as DropDownList;
            }
 
            public override bool IsInitialized
            {
                get
                {
                    return this._ddl != null;
                }
            }
 
            public override string Text
            {
                get
                {
                    return this._ddl.SelectedItem.Text;                   
                    //return this.Text.ToString();
                }
                set
                {
                    this._ddl.SelectedValue = value;
                    //this._ddl.SelectedIndex = this._ddl.Items.IndexOf(this._ddl.Items.FindByValue(value));
                }
            }
 
            protected override void AddControlsToContainer()
            {
                _ddl = new RadDropDownList();
                //_ddl = new DropDownList();
                _ddl.Skin = "Windows7";
                _ddl.DataSource = _dt;
                /*if ("" + _dt.Rows[0]["ColumnCode"] == "RuleCode") _ddl.DataValueField = "ListValueKey";
                else  _ddl.DataValueField = "ListValueLabel";*/
                if (_version == "2017") _ddl.DataValueField = "ListValueKey";
                else _ddl.DataValueField = "ListValueLabel";               
                _ddl.DataTextField = "ListValueLabel";
                int height = _dt.Rows.Count * 20;
                if(height > 200) height = 200;
                _ddl.DropDownHeight = Unit.Pixel(height);
                _ddl.DropDownWidth = Unit.Pixel(100);
                _ddl.Font.Size = FontUnit.Point(8);
                this.ContainerControl.Controls.Add(this._ddl);
            }
        }

 

So why during the save an edited row I got no exception to get the value of the selected value in my custom DropDown but I got one when I try to save a new row?

 

Thx,

Bouyez.

0
Bouyez
Top achievements
Rank 1
answered on 28 Mar 2017, 02:08 PM

I finally find it. 

In public override Text :

get -> return this._ddl.SelectedValue;   OR return this._ddl.SelectedText;    Don't know why but return the same value and don't return the text.

Tags
Grid
Asked by
Bouyez
Top achievements
Rank 1
Answers by
Bouyez
Top achievements
Rank 1
Share this question
or