2009-11-16 98 views
0

我有一个窗体窗体,其中包含浏览器导航到以表格形式发送数据的站点。我想将该表上的数据传输到应用程序,该应用程序对数据进行一些计算,然后报告计算是否成功。如果计算成功,网页浏览器应请求更多数据并重复该过程。如果不是,代码应该停止。InvokeMethod不能在窗体上工作

下面显示的代码允许第一次将数据导入到表格时正常工作。但是,调用InvokeMethod时,表中的数据不会刷新(代码未显示表明表中的数据相同)。有解决方案吗?

private void cmdRun_Click(object sender, EventArgs e) 
    { 
      //set reference to button go get a new game 
     WebBrowser WB = webBrowser1; 
     HtmlElementCollection SudokuTable; HtmlDocument Doc; 
     //set reference to the button to refresh the table 
     HtmlElement goButton = this.webBrowser1.Document.All["VeryHardLevelStr"]; 

    RunAgain: 
     Doc = WB.Document;  //get a new copy of the info 

     //Get the second form, tranfer the data and process it 
     Form FormSolver = GetSolverForm();     //set reference to form 
      //set reference to datagrid to transfer data to 
     DataGridView dGV1 = GetDGVQ1(FormSolver); 
      //set reference to button that starts processing the data 
     Button StartButton = GetNamedButton(FormSolver, "cmdStart"); 
      //set reference to checkbox to determine if the processing was ok 
     CheckBox CheckBxOK = GetNamedCheckBox(FormSolver, "ckSolutionOK"); 
      //set a reference to the table with the values 
     SudokuTable = Doc.GetElementsByTagName("TABLE"); 
      //transfer the values to a table on another form 
     TransferDataToSolvingForm(SudokuTable, dGV1); 
      //start code on second form to process the data 
     StartButton.PerformClick(); 

      //if a solution has been found close the form and request more data 
    //if not solution found let code stop 
     if (CheckBxOK.Checked)   
     { 
      //user wants to close other form if successful uf CloseOnSuccess is true 
      Boolean CloseOnSuccess = this.ckCloseSolverOnSuccess.Checked; 
      if (CloseOnSuccess) 
      { 
       FormSolver.Close();    //since a solution was arrived at close the form 
       goButton.InvokeMember("click"); //Click the key on web browser to request more data 

       while (WB.IsBusy == true)    //wait till it has retreived the data 
       { 
        System.Threading.Thread.Sleep(50); 
       } 
      } 

      goto RunAgain;     //go back a reanalyze the new data 
     } 
    } 
+0

什么被定义为 “工作”?你想要提交表单吗?或者你想要按钮的onclick事件处理程序被执行? – 2009-11-18 17:26:21

回答

0

如果我正确理解你,你在浏览器中显示表数据,并且在第一次加载后没有更新。如果是这样的情况下,确保WebBrowser.AllowNavigation设置为true:

获取或设置指示 控件是否可以在其初始页 已经被加载后,导航到 另一页面的值。

+0

谢谢,但这不是问题,因为AllowNaviation属性设置为true。 – 2009-11-17 15:58:14