I am trying to intercept writing to a cell after returning from in-place editing within in a GridDataBoundGrid. The reason is that I cannot edit a cell bound to a DataSet column containing an expression. No matter what I do, the cell is treated as read-only. I want to intercept the call so I can convert the value and put it into the proper cell in a hidden DataSet column.
ADAdministrator Syncfusion Team August 9, 2005 05:47 PM
Try subscribing to the grid.Model.SaveCellInfo event. There, you can test e.RowIndex and e.ColIndex to check what cell you are working with, and you can get the value from e.Style.CellValue so you can do something else with it. You should also set e.handled = true so the grid does not try to save the value itself.
CHChuck HillAugust 12, 2005 01:27 PM
Your solution works great for DataSet columns that contain writable data but does not work for underlying DataSet columns that contain only an expression. The GDBG cell enters edit mode, the text in the cell is selectable, but the characters in the cell refuse to change.
I want to edit these columns, intercept the values and write the results to the hidden columns that the underlying DataSet column expressions refer to.
ADAdministrator Syncfusion Team August 12, 2005 06:43 PM
To avoid the expression columns being editable, try handling the CurrentCellStartEditing event. If grid.CurrentCell.ColIndex points to one of your expression columns in your event handler, then set e.Cancel = true.
CHChuck HillAugust 15, 2005 07:24 PM
Actually, I _want_ to edit the cell and intercept the results.
ADAdministrator Syncfusion Team August 15, 2005 07:38 PM
You can try the CurrentCellValidating event. To get the new value of the cell, you can use grid.CurrentCell.Renderer.ControlText.
CHChuck HillAugust 16, 2005 01:10 PM
I tried that and it doesn''t work. I need to be able to modify the characters in the cell before any of those events are fired.
ADAdministrator Syncfusion Team August 16, 2005 01:45 PM
If you want to specify the text that appears in the cell when the cell starts editing, then handle the CurrentCellInitializeControlText event.
private void gridControl1_CurrentCellInitializeControlText(object sender, GridCurrentCellInitializeControlTextEventArgs e)
e.ControlText = "ABC";
CHChuck HillAugust 17, 2005 11:39 AM
Unfortunately, I am not making myself very clear. While the application is running the GDBG column cells enter edit mode, the cell contents are selectable for ctrl-c copy operations, but the characters in the cell cannot be changed. The keystrokes are ignored.
I want the grid cell to be truely editable where I can insert/remove characters within the cell. Because the underlying Table column does not contain data but a computed expression from another Table column, I want to intercept the modified grid cell contents and reverse-compute the value and put it into the source Table column.
The readonly flag is NOT set.
gridColumn.StyleInfo.CellType = "TextBox";
The underlying DataTable column does not contain data but contains an expression. As an example
dv = this.myGrid.Binder.DataSource as DataView;
dv.Table.Columns["area_squm"].Expression == "ISNULL(area,0) * 0.000001".
The hidden Table column "area" contains the value in sq.nm but the value is presented to the user as sq.um
Please let me know if you are still unclear about what is occuring and what I want to do.
ADAdministrator Syncfusion Team August 17, 2005 01:34 PM
Here is a sample. No matter what you type into Col1, it will store something different (that you can specify) in the DataTable. It does this by handling the grid.Model.DataProviderSaveCellInfo event.
CHChuck HillAugust 17, 2005 03:28 PM
Here''s your sample slightly modified so that it simulates my issue.
ADAdministrator Syncfusion Team August 17, 2005 04:18 PM
You cannot use this is SaveCellInfo. SaveCellInfo can be hit for many reasons, and you cannot assume that Renderer.ControlValue will have any particular value.
Suppose you write the expression as:
this.dt.Rows[e.RowIndex - 1]["Col2"] = XXXXX;
The question is exactly where do you want XXXXXX to come from? And what cell do you type in to decide that you can to set Col2 to be some value?
CHChuck HillAugust 18, 2005 12:18 PM
OK. Not only do I want to know how to modify the text within a cell in "Col3", but I want to know how to retrieve the value so I can transform and set it to the cell in "Col2".
ADAdministrator Syncfusion Team August 18, 2005 06:00 PM
I think I understand what you want now. Here is a modified sample. If uses an unbound column to offer the flexibility of editing the computed column. http://www.syncfusion.com/Support/user/uploads/GDBC_Sample_2668fdde.zip