Alex Prinias asked 2016-09-27 05:51:45 UTC
Hi guys,
I have the following handler for the TreeView_KeyDown event, which used to work nicely before updating to version 1.2.67 (for completeness, also the Before/AfterLabelEdit events):
private void tv_KeyDown(object sender, KeyEventArgs e)
{
var node = tv.SelectedNode;
if (node != null)
{
switch (e.KeyCode)
{
case Keys.Delete:
Delete(node);
break;
case Keys.Insert:
Add(node);
break;
case Keys.F2:
Edit(node);
break;
}
}
}
private void Edit(TreeNode node)
{
tv.SelectedNode = node;
node.BeginEdit();
}
private void tv_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
{
string error = String.Empty;
short nodeId = Convert.ToInt16(e.Node.Tag);
MySession.Current.BLL.UpdateReferringType(nodeId, e.Label, e.Node.Checked, out error);
if (!String.IsNullOrEmpty(error))
{
MessageBox.Show(String.Format("Error in editing TreeNode '{0}'", error));
}
tv.KeyDown += tv_KeyDown;
}
private void tv_BeforeLabelEdit(object sender, NodeLabelEditEventArgs e)
{
tv.KeyDown -= tv_KeyDown;
}
When I press now F2, I get into editing mode for the selected node Label, but when I press either Enter to accept or Esc to discard changes I get the attached Application Error, the changes are not accepted (or discarded) and, after the Error, the KeyDown event does not fire anymore, possibly because it is detached by the BeforeLabelEdit and is not re-attached by the AfterLabelEdit which does not fire (because of the error).
Any ideas?
Best,
Alex
Alex Prinias asked 2016-09-27 05:51:45 UTC
Hi guys,
I have the following handler for the TreeView_KeyDown event, which used to work nicely before updating to version 1.2.67 (for completeness, also the Before/AfterLabelEdit events):
private void tv_KeyDown(object sender, KeyEventArgs e)
{
var node = tv.SelectedNode;
if (node != null)
{
switch (e.KeyCode)
{
case Keys.Delete:
Delete(node);
break;
case Keys.Insert:
Add(node);
break;
case Keys.F2:
Edit(node);
break;
}
}
}
private void Edit(TreeNode node)
{
tv.SelectedNode = node;
node.BeginEdit();
}
private void tv_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
{
string error = String.Empty;
short nodeId = Convert.ToInt16(e.Node.Tag);
MySession.Current.BLL.UpdateReferringType(nodeId, e.Label, e.Node.Checked, out error);
if (!String.IsNullOrEmpty(error))
{
MessageBox.Show(String.Format("Error in editing TreeNode '{0}'", error));
}
tv.KeyDown += tv_KeyDown;
}
private void tv_BeforeLabelEdit(object sender, NodeLabelEditEventArgs e)
{
tv.KeyDown -= tv_KeyDown;
}
When I press now F2, I get into editing mode for the selected node Label, but when I press either Enter to accept or Esc to discard changes I get the attached Application Error, the changes are not accepted (or discarded) and, after the Error, the KeyDown event does not fire anymore, possibly because it is detached by the BeforeLabelEdit and is not re-attached by the AfterLabelEdit which does not fire (because of the error).
Any ideas?
Best,
Alex