I am learning the C# programming language and am making a payroll application add-on for SAP business One. I have a TreeView and need to have the name of a node appear on a TextBox after a use clicks on that node or when he presses a button "Add", preferably on click only. I am using Visual Studio 2010 and Microsoft SQL Server 2008.
Scenario:
- Component                        - Parent
          Earnings                     - child
              Housing Allowance                  - content of child
              Mobile Phone Allowance             - clicked and highlighted node
              Mileage Allowance
          Deductions                   - child
In the above, I would like a way such that if a user clicks on "Mobile Phone Allowance", and it is highlighted, 'Mobile Phone Allowance' appears on a textbox. Im not sure if this can be done without having an Add button.
The Earnings and Deduction children are populated from a database. I need the above to make a Payroll calculator.
My Code:
private void PayrollFormulaBuilder_Load(object sender, EventArgs e)
{
    // Get service instance
    var earnDeductMasterService = Program.Kernel.Get<IEarnDeductMasterService>();
    //Query database for all records that have earnings
    var earnings = from ed in earnDeductMasterService.GetAllEarnDeductMasters()
                   where ed.U_PD_type.Trim().Equals("Earnings".Trim(), StringComparison.CurrentCultureIgnoreCase)
                   select ed.U_PD_description;
    if (earnings.Any(x => x != null))
    {
        //To populate subtree Earnings with U_PD_description  = Earnings results
        List<string> earningList = new List<string>(earnings) { };
        //adding all earnings to "Earnings" node
        foreach (string earning in earningList)
        {
            treeView1.Nodes[0].Nodes[0].Nodes.Add(earning);
        }
    }
    else
    {
        //Nothing to populate            
    }
    //Query database for all records that have deductions
    var deductions = from ed in earnDeductMasterService.GetAllEarnDeductMasters()
                     where开发者_JS百科 ed.U_PD_type.Trim().Equals("Deductions".Trim(), StringComparison.CurrentCultureIgnoreCase)
                     select ed.U_PD_description;
    if (deductions.Any(x => x != null))
    {
        //To populate subtree Deductions with U_PD_description = Deductions results
        List<string> deductionList = new List<string>(deductions) { };
        //adding all earnings to "Earnings" node
        foreach (string deduction in deductionList)
        {
            treeView1.Nodes[0].Nodes[1].Nodes.Add(deduction);
        }
    }
    else
    {
        //Nothing to populate            
    }
}
I would imagine I would have to setup a method to capture this...but I'm not sure
private void treeView1_DoubleClick(object sender, EventArgs e)
{
    if (inputStatus)
    {
        formula_display.Text += "something here"  // my Richtextbox for showing input
    }
    else
    {
        formula_display.Text = "something here"
        inputStatus = true;
    }
}
Could you use the TreeView AfterSelect event in place of your "something here" ?
treeview1.AfterSelect += new TreeViewEventHandler(treeview1_AfterSelect);
..and..
void treeview1_AfterSelect(object sender, TreeViewEventArgs e)
{
    formula_display.Text = e.Node.Text;
}
You may add an event handler to NodeMouseClick event of your treeview:
treeView1.NodeMouseClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(treeView1_NodeMouseClick);
The event handler should be as follows:
private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            //Identify whether the user has clicked the MobilePhoneAllowance node by
            //using the properties of e.Node
            //Then set TextBox.Text to the required text in the node
        }
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论