我有一个用c#编码的程序,它接收来自不同来源和多个IP地址的UDP数据包。
我创建了一个数据表,用于存储链接到源的所有IP地址和信息,我尝试在运行时在程序中显示该表。
由于程序一直在监听UDP数据包,因此应该实时更新表的查看。
我搜索过Datagridview,但是我没有成功使用它。
我想以非常简单的方式在屏幕上显示如下内容: Data Viewing
static void Main(string[] args)
{
DataTable CommunicationTable = new DataTable();
initDataTableCommunication(CommunicationTable);
senderIdentifier SmartphoneTest = new senderIdentifier();
SmartphoneTest.addressIP = "192.120.120.0";
SmartphoneTest.message = "Started";
SmartphoneTest.port = 11000;
newEntryDateTableCom(SmartphoneTest, CommunicationTable);
senderIdentifier SmartphoneTest2 = new senderIdentifier();
SmartphoneTest2.addressIP = "192.120.45.9";
SmartphoneTest2.message = "Done";
SmartphoneTest2.port = 11000;
newEntryDateTableCom(SmartphoneTest2, CommunicationTable);
这里我“手动”完成了DataTable,但是新条目将通过接收UDP数据包来创建
目前,我只能通过使用DataTable监视器上的“范围”(Visual Studio)来使用Debug可视化DataTable
抱歉我的英语不好,并提前致谢
答案 0 :(得分:0)
您必须创建一个新的Windows窗体项目并删除DataGridView
控件。将您的CommunicationTable
定义为新创建的表单的字段,并将CommunicationTable
初始化放在初始化代码中的某个位置(表单的构造函数是一个很好的候选者)。此初始化还应将DataSource
的{{1}}属性设置为DataGridview
。
然后在单独的线程中运行UDP侦听例程并使其更新CommunicationTable
。但是不要忘记使用CommunicationTable
来更新GUI线程中的数据。
这是一个简化的例子:
Form.Invoke()