Edited solution :
You should know that when the cursor is in the cell (in edit mode), and you press a button, it's not the TreeList
who send the KeyDown
event, but the RepositoryItemButtonEdit
. So, you should handle the event also for the RepositoryItemButtonEdit
.
To not duplicate code, I've wrote one handler 'onKeyDown
', in whitch I verify who is the sender.
treeList1.KeyDown += onKeyDown;
riButtonEdit.KeyDown += onKeyDown;
And here is a code exemple showing you how to handle the KeyDown
event for both treeList
and repositoryButtonEdit
, and set the cell value to null
:
private void onKeyDown(object sender, KeyEventArgs e)
{
// Test if the button pressed is the delete button
if (e.KeyCode != Keys.Delete)
return;
// Test if the focused column is colValue
if (treeList1.FocusedColumn != colValue)
return;
// Set the cell value to null
treeList1.FocusedNode.SetValue(colValue, null);
// If it's the ButtonEdit who send the event, make it's EditValue null
var btnEdit = sender as ButtonEdit;
if (btnEdit != null)
{
btnEdit.EditValue = null;
}
}