2

接続されたハードウェアと通信できるアプリケーションが 1 つあります。ハードウェアの電源を入れると、ハードウェアは継続的にデータをアプリケーションに送信します。アプリケーションでハードウェアからデータを読み取ることができます。

ここで、このデータを継続的にグリッド ビューに記録したいと考えています (アプリケーションがデータを受信するたびに、新しい行をグリッド ビューに追加し、その行にデータを入力する必要があります)。

(または、1 秒ごとにグリッド ビューに新しい行を追加し、実行時にデータを追加する方法を教えてください)

助けてください。私はC#が初めてです。

ありがとう。

4

2 に答える 2

1

オブジェクトまたは変数のどこかでデータを取得すると、これが機能します。

// suppose you get the data in the object test which has two fields field1 and field2, then you can add them in the grid using below code:

grdView.Rows.Add(test.field1, test.field2);

私はそれがあなたを助けることを願っています.. :)

于 2013-07-30T06:35:22.843 に答える
1

これがあなたのためのデモです。あなたのデータはInfo以下に定義されているタイプであると思いますProperties。データ構造(ハードウェアから受信したもの)に応じて、それに応じて変更できます。

public partial class Form1 : Form {
   public Form1(){
      InitializeComponent();
      dataGridView1.AllowUserToAddRows = false;//if you don't want this, just remove it.
      dataGridView1.DataSource = data;
      Timer t = new Timer(){Interval = 1000};
      t.Tick += UpdateGrid;
      t.Start();
   }     
   private void UpdateGrid(object sender, EventArgs e){
      char c1 = (char)rand.Next(65,97);
      char c2 = (char)rand.Next(65,97);
      data.Add(new Info() {Field1 = c1.ToString(), Field2 = c2.ToString()});
      dataGridView1.FirstDisplayedScrollingRowIndex = data.Count - 1;//This will keep the last added row visible with vertical scrollbar being at bottom.
   }
   BindingList<Info> data = new BindingList<Info>();
   Random rand = new Random();
   //the structure of your data including only 2 fields to test
   public class Info
   {
        public string Field1 { get; set; }
        public string Field2 { get; set; }
   }  
}
于 2013-07-30T07:37:11.080 に答える