Cell Editing
Hi,
I currently have certain cells which are editable and which the user can directly type into. The behavior I notice is that the user has to hit "Enter" or click on another cell before the value is stored in the bound data object. Is there a way that we can bind the value that has been typed into the object without either hitting "enter " or clicking on another cell. I'm basically looking for behavior like a text box, where what we type in is the value we get out.
Thanks,
Deepak
0
-
Hi,
You can use a custom editor:
internal class MyEditor : UITypeEditorEx
{
public override StopEditReason EditCell(IGridEditorService service, Cell cell, StartEditReason reason)
{
using (var control = new TextBox())
{
control.BackColor = Color.BurlyWood;
//control
control.KeyDown += (sender, args) =>
{
//Key is pressed here. Set value
cell.Text = "200";
//or
cell.Value = 200;
service.CloseCellControl(StopEditReason.UserStop);
};
return service.CellEditControl(control, cell.VirtualBounds, reason);
}
}
}
//Use attributes to set the editor
public class Order
{
[Editor(typeof(MyEditor), typeof(UITypeEditor))]
public decimal Amount { get; set; }
}
//or set it per column:
grid.Headers[0]["MyColumn"].Editor = new MyEditor();
//or you can also set this editor dynamically when the user clicks on the cell
grid.CellEditor += delegate(object sender, GridCellEditableEventArgs e)
{
e.Editable = true;
e.Editor = new MyEditor();
};Best regards,
Dapfor
0
Please sign in to leave a comment.
Comments
1 comment