2017-01-24 6 views
0

コードのこの部分を実行しようとしているときにエラーメッセージが表示されないので、ここで何が起こっているのかわかりません。C#辞書が機能していませんか?

基本的にはそのオプションがmenue

と同様に、ドロップダウンから選択されたとき、私は「停電」を選択した場合、それはにその内容を置く必要があるドロップダウンから、リッチテキストボックスに辞書からテキストを置くことになってリッチテキストボックス

public partial class Form1 : Form 
{ 
    public Dictionary<string, string> templates = new Dictionary<string, string>(); 

    public Form1() 
    { 
     // Templates 
     templates.Add("Outage", "Server Name: \nTest: \nTest (test): \n"); 
     templates.Add("Out", "test: \nTest: \nTest:"); 
     templates.Add("Custom", @"C:\Users\johnathan_jackson\Downloads\Remedy Tool\Templates\custom templates\test.txt"); 
     templates.Add("Test", "Server Name: \nTest: \nTest: \n"); 
     templates.Add("Basic", "OS: \nIP Address: \nApplications affected: \nWhen did this last work: \n Number of users affected: \nSpecific error message: \nTroubleshooting steps taken \nDetailed Resolution \nIf not service resolvable, Why:"); 
     templates.Add("Xerox", "Serial Number (mandatory): \nAsset Number: \nContact Phone Number: \nContact e-mail address: \nFull Address: \nDescription of the Supplies that are needed: \nPart # (if customer has it): \nError message (if any): \nLocation (Building/Floor/etc): \nModel #: \n"); 

     NavigateURL navigateBrowser = new NavigateURL(); 

     InitializeComponent(); 

     Remedy_Automate.AllowNavigation = true; 
     Remedy_Automate.ScriptErrorsSuppressed = true; 
     Remedy_Automate.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(navigateBrowser.DocumentState); 

     // GetInfo from Remedy to these controls 
     navigateBrowser.cIncidentID = incidentID_Entry; 
     navigateBrowser.cEmployeeID = employeeID_Entry; 
     navigateBrowser.cEmployeeName = employeeName_Entry; 
     navigateBrowser.cPhoneNumber = phoneNumber_Entry; 

     navigateBrowser.cNotes = Notes_Entry; 

     getinfo.Click += new System.EventHandler(navigateBrowser.GetInfoClick); 
     sendinfo.Click += new System.EventHandler(navigateBrowser.ModifyInfo); 

     browserTabControl.Selecting += browserTabControl_Selecting; 
     browserTabControl.HandleCreated += browserTabControl_HandleCreated; 

     wTemplates.DropDownStyle = ComboBoxStyle.DropDownList; 

     // set browser control in 'cNavigateURL' class 
     navigateBrowser.BrowserInstance = Remedy_Automate; 
     navigateBrowser.NavigateToUrl("http://fit.honeywell.com/arsys"); 

    }// Form1 

    private void sendinfo_click(object sender, EventArgs e) 
    { 
     string notestext = Notes_Entry.Text; 
     Console.WriteLine(notestext); 
    } 

    private void template_selected(object sender, EventArgs e) 
    { 
     String pTempText = wTemplates.Text; 
     Console.WriteLine(pTempText); 
     switch(pTempText) 
     { 
      case "Outage": 
       Notes_Entry.Text = templates[pTempText]; 
       break; 
      case "Basic": 
      Notes_Entry.Text = templates[pTempText]; 
       break; 
      case "Custom": 
       Notes_Entry.Text = templates[pTempText]; 
       break; 
      case "Out": 
       Notes_Entry.Text = templates[pTempText]; 
       break; 
     } 
+1

InitializeComponent(); Form1コンストラクターの最初の位置にある必要があります –

+1

何かエラーが表示されていますか?あなたは例外を取得したときに変数値が何かを確認するために、デバッガでそれを実行しましたか? –

+4

特に、スイッチブロックは必要ありません。ディクショナリにキーが含まれているかどうかを確認し、そうであればそれを設定します。すべてのケースブロックに同じコードがあることに注目してください。 – LarsTech

答えて

1

私はあなたのコンボボックスにあなたの綴りをどこにバインドするのか分かりません。 (「」、「アイテムの選択」)という項目0のようなリアルな選択ではないので、私はまた、あなたの辞書の上部に別のエントリを追加することをお勧めします

wTemplates.DisplayMember = "Key"; 
wTemplates.ValueMember = "Value"; 
wTemplates.DataSource = new BindingSource(templates, null); 

:あなたは、次の追加する必要があります。これは、コンボボックスが初めて塗りつぶされたときにselected_itemイベントが発生するためです。

だからあなたのコードは、Form1の()には次のようになります。

 // Templates 
     templates.Add("Select Item", ""); 
     templates.Add("Outage", @"Server Name: \nTest: \nTest (test): \n"); 
     templates.Add("Out", @"test: \nTest: \nTest:"); 
     templates.Add("Custom", @"C:\Users\johnathan_jackson\Downloads\Remedy Tool\Templates\custom templates\test.txt"); 
     templates.Add("Test", @"Server Name: \nTest: \nTest: \n"); 
     templates.Add("Basic", @"OS: \nIP Address: \nApplications affected: \nWhen did this last work: \n Number of users affected: \nSpecific error message: \nTroubleshooting steps taken \nDetailed Resolution \nIf not service resolvable, Why:"); 
     templates.Add("Xerox", @"Serial Number (mandatory): \nAsset Number: \nContact Phone Number: \nContact e-mail address: \nFull Address: \nDescription of the Supplies that are needed: \nPart # (if customer has it): \nError message (if any): \nLocation (Building/Floor/etc): \nModel #: \n"); 

     wTemplates.DropDownStyle = ComboBoxStyle.DropDownList; 

     wTemplates.SelectedIndexChanged += template_selected; 

     wTemplates.DisplayMember = "Key"; 
     wTemplates.ValueMember = "Value"; 
     wTemplates.DataSource = new BindingSource(templates, null); 

は、その後、ハンドラを持って、実際にそれのコードを持っています。

private void template_selected(object sender, EventArgs e) 
    { 
     String pTempText = wTemplates.Text; 
     Console.WriteLine(pTempText); 
     switch (pTempText) 
     { 
      case "Outage": 
       Notes_Entry.Text = templates[pTempText]; 
       break; 
      case "Basic": 
       Notes_Entry.Text = templates[pTempText]; 
       break; 
      case "Custom": 
       Notes_Entry.Text = templates[pTempText]; 
       break; 
      case "Out": 
       Notes_Entry.Text = templates[pTempText]; 
       break; 
     } 
    } 
+0

感謝します!それは働いている。あなたがそれを見たら、そのような単純な修正があります。本当にありがとう! – Imcoolyourenot

+0

私はお手伝いできるとうれしいです、あなたの問題を解決した場合は、答えとしてマークしてください。ありがとう! – JackInMA

関連する問題