private void TreeListView1_MouseClick(object sender, MouseEventArgs e) { string canData = ""; string msgName = ""; string tmp = ""; tm = new TableMsg(dataTable); TreeListViewItem msgitem = null; TreeListViewItem item = treeListView1.GetItemAt(new System.Drawing.Point(e.X, e.Y)); if (item.Text.Equals("messageName ")) { msgitem = item; string datastr = ""; foreach (ListViewSubItem msgdata in msgitem.SubItems) { tmp = msgdata.Text; } canData = tmp.Split(' ')[1]; msgName = tmp.Split(' ')[0]; Decode.DecodeCANSignal(canData, msgName, ref dataTable, out tm); updateUi(tm); } else { msgitem = item.Parent; string datastr = ""; foreach (ListViewSubItem msgdata in msgitem.SubItems) { tmp = msgdata.Text; } canData = tmp.Split(' ')[1]; msgName = tmp.Split(' ')[0]; Decode.DecodeCANSignal(canData, msgName, ref dataTable, out tm); Dictionary <string, string> returnedDatatmp = new Dictionary <string, string>(); foreach (string key in tm.ReturnedData.Keys) { if (key.Equals(item.Text)) { returnedDatatmp.Add(key, tm.ReturnedData[key]); } } tm.ReturnedData = returnedDatatmp; updateUi(tm); } //Thread th = new Thread(new ParameterizedThreadStart(UpdateTableThread.updateUi)); //th.Start(tm); }
public static void updateUi(object tablemsg) { Console.WriteLine("this is a thread!!"); TableMsg tm = (TableMsg)tablemsg; for (int j = 0; j < 8; j++) { Console.WriteLine("this is a thread!!" + tm.Binarydata[j]); } DataTable table = (DataTable)tm.DataTable; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { table.Rows[i].ItemArray[j] = tm.Binarydata[i * 8 + j]; } } }
public void updateUi(object tablemsg) { clearColor(); tm = (TableMsg)tablemsg; dataTable.Clear(); for (int i = 0; i < 8; i++) { DataRow dr = dataTable.NewRow(); for (int j = 0; j < 8; j++) { //两种存取方式 //dataTable.Rows[0].ItemArray[0] = 0; dr[7 - j] = tm.Binarydata[8 * i + j]; } dataTable.Rows.Add(dr); } for (int i = 0; i < 8; i++) { dataGridView1.Columns[i].Width = (int)(dataGridView1.Width / (8.53)); } //dataGridView1.DataSource = dataTable; int num = 0; foreach (string str in tm.ReturnedData.Values) { if (str.Split('@')[1].Equals("0+")) { string[] startandlen = str.Split('@')[0].Split('|'); int startpos = int.Parse(startandlen[0]); int len = int.Parse(startandlen[1]); int row = startpos / 8; int col = startpos % 8; for (int i = 0; i < len; i++) { tablecolor[row][7 - col] = colors[num]; col--; if (col < 0) { col = 7; row++; } } } else { string[] startandlen = str.Split('@')[0].Split('|'); int startpos = int.Parse(startandlen[0]); int len = int.Parse(startandlen[1]); int row = startpos / 8; int col = startpos % 8; for (int i = 0; i < len; i++) { tablecolor[row][7 - col] = colors[num]; col++; if (col > 7) { col = 0; row++; } } } num++; } dataGridView1.Refresh(); }