2011-07-15 8 views
0

私はC#プログラミング言語を学び、SAP Business Oneの給与計算アプリケーションアドオンを作成しています。私はTreeViewを持っていて、そのノードの使用がクリックされた後、または彼が「Add」ボタンを押すと、TextBox上にノードの名前を表示する必要があります。私は、Visual Studio 2010とMicrosoft SQL Server 2008のノードの内容をクリックしてテキストボックスに追加した

シナリオ使用しています:上記で

- Component      - Parent 
      Earnings      - child 
       Housing Allowance     - content of child 
       Mobile Phone Allowance    - clicked and highlighted node 
       Mileage Allowance 
      Deductions     - child 

を、私はそのようなユーザーは、「携帯電話手当」をクリックし、それがある場合はその方法をしたいと思いますテキストボックスに「Mobile Phone Allowance」と表示されます。 Addボタンを押さなくてもこれができるかどうかわかりません。

収益と控除の子は、データベースから設定されます。私は上記の給与計算機を作る必要があります。

マイコード:

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 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    
    } 
} 

私はセットアップにこれをキャプチャする方法を持っているでしょう想像...しかし、私は

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; 
    } 
} 

答えて

2

ツリービューAfterSelectイベントを使用することができますかわかりませんあなたの「ここに何か」の代わりに?

treeview1.AfterSelect += new TreeViewEventHandler(treeview1_AfterSelect); 

..and ..

void treeview1_AfterSelect(object sender, TreeViewEventArgs e) 
{ 
    formula_display.Text = e.Node.Text; 
} 
+0

申し訳ありませんが、void treeview1_AfterSelectを編集してツリーを無効にしましたView1_DoubleClick –

+0

代わりにNodeMouseDoubleClickに変更すると、e.Nodeの機能が得られます – fatty

+0

コードを少し変更しましたが、問題を解決しました。ありがとう。 –

0

あなたは、あなたのツリービューのNodeMouseClickイベントにイベントハンドラを追加することがあり、次のよう

treeView1.NodeMouseClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(treeView1_NodeMouseClick); 

イベントハンドラは次のようになります。

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 
     } 
関連する問題