我想访问方法“GetApplicationName”中的“dataGridView1”,它本身位于“ExternalApplication”类中。 (类和方法名称不具有描述性)“v”将对应于“dataGridView1”中的行,在将“v”从字符串转换为int之后,我想使用它来选择并突出显示该数据视图中的行。但是在那个方法里面“dataGridView1”超出了范围。我认为做上述事情比较容易 - 试图使“v”等同于全局,这似乎需要更多的工作(?)不确定。引用的代码到目前为止工作...我已经尝试了很多东西但是无法得到它。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using MySql.Data.MySqlClient;
namespace houseDB1
{
public partial class Form1 : Form
{
private string server;
private string database;
private string uid;
private string password;
private MySqlConnection connection;
public Form1()
{
InitializeComponent();
webBrowser1.ObjectForScripting = new ExternalApplication();
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Navigate("127.0.0.1/box3.php");
server = "localhost";
database = "realestate_db";
uid = "root";
password = "";
string connectionString;
connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
connection = new MySqlConnection(connectionString);
connection.Open();
MySqlDataAdapter mySqlDataAdapter;
mySqlDataAdapter = new MySqlDataAdapter("SELECT `ID`, `lat` , `long` FROM `house` ", connection);
DataSet DS = new DataSet();
mySqlDataAdapter.Fill(DS);
dataGridView1.DataSource = DS.Tables[0];
}
private void webBrowser1_DocumentCompleted_1(object sender, WebBrowserDocumentCompletedEventArgs e)
{
}
[ComVisible(true)]
public class ExternalApplication
{
public void GetApplicationName(string v) // getting values from webbrowser
{
MessageBox.Show("ZZTOP" + v);
//return "The application";
}
}
private void splitContainer1_Panel2_Paint(object sender, PaintEventArgs e)
{
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
}
}
答案 0 :(得分:0)
您可以将dataGridView1
的引用传递给GetApplicationName
方法。