2017-01-24 4 views
0

코드의이 부분을 실행하려고 할 때 오류 메시지를 표시하지 않으므로 정확히 무슨 일이 일어나고 있는지 잘 모릅니다.C# 사전이 작동하지 않습니까?

기본적으로는이 옵션을 MENUE

처럼 드롭 다운 메뉴에서 선택했을 때 내가 "정전"을 선택하는 경우가로 그 내용을 넣어야 드롭 다운에서를 RichTextBox에 사전에서 텍스트를 넣어하기로 richtextbox

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

다음과 같은 추가해야 . 이는 combo box가 처음 채워질 때 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

관련 문제