I am trying to have a Button
which
- gets
Enabled
when a node in theTreeView
is selected - gets
Disabled
when a node in theTreeView
loses focus
My Form
have two TreeViews
:
- TreeView containing Books
- TreeView containing Loans
and when one of them has the current selection I want the other to de-select its item.
I also have a ComboBox
in the Form
.
When the TreeView
with Loan(s) has an item selected I want to press a button to return this loan. But as soon as I try to press the button it gets disabled and I cannot interact with it.
I have tried to solve it like this:
private void treeViewLoans_AfterSelect(object sender, TreeViewEventArgs e)
{
ReturnLoanButtonCheck();
}
private void treeViewLoans_Leave(object sender, EventArgs e)
{
treeViewLoans.SelectedNode = null;
ReturnLoanButtonCheck();
}
private void ReturnLoanButtonCheck()
{
if (treeViewLoans.SelectedNode == null)
buttonReturnLoan.Enabled = false;
else if (treeViewLoans.SelectedNode != null)
buttonReturnLoan.Enabled = true;
}
When I try to press the button the ComboBox gets focus instead.
What am I doing wrong here?