I had the following code to create columns with texteditorprovider (multiline) at run time. However, I found that the cell will become single-line editor after an update to the cell and save (rebind). Could you please let me know how to make the maintain the multiline editor after the rebind? Thank you so much.
<Code for webdatagrid in aspx>
<ig:WebDataGrid ID="TableDetailGrid" runat="server" ClientIDMode="Static" Height="650px" Width="100%" EnableAjax ="True" EnableAjaxViewState="True" EnableViewState ="True" EnableDataViewState="True OnRowAdding="TableDetailGridRowAdding" OnRowUpdating="TableDetailGridRowUpdating" OnRowsDeleting="TableDetailGridRowDeleting" OnColumnSorted="TableDetailGridRowSorted" OnDataFiltering="TableDetailGridDataFiltering">
<Code to create columns during Page_Load in the code behind>
private void CreateColumns(DataTable theWholeTable, string tableName, int columnWidth) { //create editing core behaviour TableDetailGrid.Behaviors.CreateBehavior<Activation>(); TableDetailGrid.Behaviors.Activation.Enabled = true; TableDetailGrid.Behaviors.CreateBehavior<EditingCore>(); TableDetailGrid.Behaviors.EditingCore.AutoCRUD = false; TableDetailGrid.Behaviors.EditingCore.BatchUpdating = true; TableDetailGrid.Behaviors.EditingCore.EditingClientEvents.RowsDeleting = "RowDeleting_Handler"; TableDetailGrid.Behaviors.EditingCore.EditingClientEvents.RowUpdated = "RowUpdated_Handler"; TableDetailGrid.Behaviors.EditingCore.EditingClientEvents.CellValueChanged = "CellValueChanged_Handler"; TableDetailGrid.Behaviors.EditingCore.EditingClientEvents.BatchUpdateUndone = "BatchUpdateUndone_Handler"; TableDetailGrid.Behaviors.EditingCore.Enabled = true; //create CellEditing behaviour TableDetailGrid.Behaviors.EditingCore.Behaviors.CreateBehavior<CellEditing>(); //TableDetailGrid.Behaviors.EditingCore.Behaviors.CellEditing.CellEditingClientEvents.EnteringEditMode = // "CellEditing_EnteringEditMode_Handler"; //create RowAdding behaviour TableDetailGrid.Behaviors.EditingCore.Behaviors.Add( TableDetailGrid.Behaviors.EditingCore.Behaviors.CreateBehavior<RowAdding>()); TableDetailGrid.Behaviors.EditingCore.Behaviors.RowAdding.EditModeActions.EnableOnActive = true; TableDetailGrid.Behaviors.EditingCore.Behaviors.RowAdding.EditModeActions.EnableOnKeyPress = true; TableDetailGrid.Behaviors.EditingCore.Behaviors.RowAdding.EditModeActions.MouseClick = EditMouseClickAction.Single; TableDetailGrid.Behaviors.EditingCore.Behaviors.RowAdding.Enabled = true; TableDetailGrid.Behaviors.EditingCore.Behaviors.RowAdding.Alignment = AddNewRowAlignment.Top; TableDetailGrid.Behaviors.EditingCore.RowAdding += new Infragistics.Web.UI.GridControls.RowAddingHandler(TableDetailGridRowAdding); TableDetailGrid.Behaviors.EditingCore.Behaviors.RowAdding.AddNewRowClientEvents.EnteringEditMode = "AddRow_EnteringEditMode_CancelEventIfReadOnly"; TableDetailGrid.Behaviors.EditingCore.Behaviors.RowAdding.AddNewRowClientEvents.ExitedEditMode = "AddRow_ExitEditMode_Handlder"; //create RowDeleting behaviour TableDetailGrid.Behaviors.EditingCore.Behaviors.Add( TableDetailGrid.Behaviors.EditingCore.Behaviors.CreateBehavior<RowDeleting>()); TableDetailGrid.Behaviors.EditingCore.Behaviors.RowDeleting.Enabled = true; //get readonly column names var readOnlyColumnNames = GetReadOnlyColumnNamesByTable(tableName); var textprovider = new TextEditorProvider(ID = "MultilineTextProvider"); textprovider.EditorControl.TextMode = TextBoxMode.MultiLine; TableDetailGrid.EditorProviders.Add(textprovider); foreach (DataColumn column in theWholeTable.Columns) { var theColumn = new BoundDataField(true); theColumn.Key = column.ColumnName; theColumn.Header.Text = column.Caption; theColumn.DataFieldName = column.ColumnName; theColumn.DataType = "System.String"; theColumn.Width = columnWidth; theColumn.EnableMultiline = true; TableDetailGrid.Columns.Add(theColumn); //create column settings var columnSetting = new EditingColumnSetting(); columnSetting.ColumnKey = column.ColumnName; columnSetting.ReadOnly = (readOnlyColumnNames.Contains(column.ColumnName, StringComparer.InvariantCultureIgnoreCase) || string.Equals(column.ColumnName, Session["PrimaryKeyName"].ToString(), StringComparison.InvariantCultureIgnoreCase)); //if (string.Equals(tableName, "dbo.CustomColumn", StringComparison.InvariantCultureIgnoreCase) && // string.Equals(column.ColumnName, "SourceColumn", StringComparison.InvariantCultureIgnoreCase)) //{ if (!columnSetting.ReadOnly && column.DataType == typeof(System.String)) { columnSetting.EditorID = textprovider.ID; } //} TableDetailGrid.Behaviors.EditingCore.Behaviors.CellEditing.ColumnSettings.Add(columnSetting); } }
<Code rebind datagrid after the save>
private void RebindGrid(string tableName) { //get the table again and rebind the table to grid after the update DataTable tableSource = new DataTable(); tableSource = GetTableRows(tableName); TableDetailGrid.ClearDataSource(); ClearFilterSetting(); TableDetailGrid.DataKeyFields = Session["PrimaryKeyName"].ToString(); TableDetailGrid.DataSource = tableSource; TableDetailGrid.DataBind(); TableDetailGrid.RequestFullAsyncRender(); Session["tableContent"] = TableDetailGrid.DataSource; }
Hello Andrew,
In this scenario calling ClearDataSource if the source table has not changed should not be necessary and may in fact be clearing the editing behavior's column settings. I have not been able to reproduce the described issue so far, any additional information such as product version used would be greatly appreciated.
I would suggest testing whether the column settings in question are still applied on the grid after the first update. This could be done using something similar to:
ig_controls.WebDataGrid1.get_behaviors().get_editingCore().get_behaviors().get_cellEditing().get_columnSettings()
Please do not hesitate to contact me with any updates or questions.