我有一个填充数据的 DataTable,有名为“ALIASNUM”和“VALUE”的列。我正在尝试获取“ALIASNUM”列中所有项目的值并将其放入“VALUE”列。
这是我的代码:
NDde.Client.DdeClient client = new NDde.Client.DdeClient("TR1EMCodeEmulator", "Command");
client.Connect();
DataRow[] rowList = dataTable1.Select("ALIASNUM > 0 ");
foreach (DataRow dr in rowList)
{
string alias = dr["ALIASNUM"].ToString();
string currentValue = client.Request(alias, 60000);
dr["VALUE"] = currentValue;
}
此代码工作正常,但我想使用 StartAdvise 使这些值成为实时值并在 dataGridView 上显示具有实时值的数据表,我该怎么做?
这是使用 startadvise 后的完整代码:
1- 建议处理程序
private void client1_Advise(Object sender, NDde.Client.DdeAdviseEventArgs e)
{
DataRow[] rowList1 = dataTable1.Select("ALIASNUM = " + e.Item);
if (rowList1.Length > 0)
{
rowList1[0]["VALUE"] = e.Text;
}
}
2- DDE 连接
string ddeApplication1 = "";
string ddeTopic1 = "";
ddeApplication1 = "TR1EMCodeEmulator";
ddeTopic1 = "Command";
NDde.Client.DdeClient client1 = new NDde.Client.DdeClient(ddeApplication1, ddeTopic1);
client1.Connect();
3- 开始建议
//Get the values for the requested data through the DDE connections.
client1.Advise += client1_Advise;
DataRow[] rowList1 = dataTable1.Select("ALIASNUM > 0 ");
foreach (DataRow dr1 in rowList1)
{
string alias = dr1["ALIASNUM"].ToString();
client1.StartAdvise(alias, 1, true, 60000);
}