How to retain the text editing capability of a cell when the field is binded to a custom editor?
Hi Team,
I use .net grid with threadsafebindinglist<T> as datasource, in my custom object T. As a number of grid's columns share similar cell appearance formatting, I binded some fields with a custom editor CustomEditor as below.
In one grid
[Field(A)]
[Editor(typeof(CustomEditor), typeof(UITypeEditor))]
public decimal A
{
get { return m_A; }
set
{
m_A= value;
}
}
In another grid
[Field(B)]
[Editor(typeof(CustomEditor), typeof(UITypeEditor))]
public decimal B
{
get { return m_B; }
set
{
m_B= value;
}
}
The problem comes when column A in grid1 is expected to be editable, where column B is not, but after I binded both columns to the same CustomEditor, both columns becomes non-editable.
I don't know how to make use of overriding EditCell/EditValue inside CustomEditor, as it seems like I must have to create a custom control(e.g. button, slider..etc) but cannot simply keep the original text editing capability.
Not sure if my question is clear enough. Please let me know if you need more information
Cheers,
Juno
-
Dear Juno,
You can use any control to edit cells. Please find an example demonstrating how to create and use the custom editor:
class MyEditor : UITypeEditorEx
{
public override StopEditReason EditCell(IGridEditorService service, Cell cell, StartEditReason reason)
{
using(TextBox control = new TextBox())
{
//Setup control
control.Text = cell.Text;
control.BackColor = Color.BurlyWood;
//control
control.KeyDown += (sender, args) =>
{
//Key is pressed here
};
//edit data in the control
service.CellEditControl(control, cell.VirtualBounds, reason);
//cell.Text = control.Text;
// or
//cell.Value = ...
}
}
}Best regards,
Dapfor
0
Please sign in to leave a comment.
Comments
1 comment