【发布时间】:2017-05-31 10:47:47
【问题描述】:
DataRow row = table.NewRow(); // Insert New row in datagridview
if (ByteArrayToHexString(buffer).StartsWith("AA") && ByteArrayToHexString(buffer).Substring(6, 2).StartsWith("11"))
{
table.Rows.Add(row); // Add new row
row["Source"] = string.Format("{0}", "ABUS_L/R"); // Insert source name in row
row["System Time"] = DateTime.Now.ToString("HH:mm:ss:fff"); // Insert time in row
//row["Source"] = ByteArrayToHexString(buffer).Substring(9, 2);
row["T.S Begin"] = ByteArrayToHexString(buffer).Substring(8, 8); // Insert TS Begin
row["T.S End"] = ByteArrayToHexString(buffer).Substring(16, 8); // Insert TS End
row["Length"] = ByteArrayToHexString(buffer).Substring(24, 2); // Insert length Field
row["Data"] = ByteArrayToHexString(buffer).Substring(26, 2); // Insert Data field
row["CRC"] = ByteArrayToHexString(buffer).Substring(28, 2); // Compare CRC field with Protocol & validate the information
row["CRC_PC"] = crc8.ComputeChecksum(buffer); // Compute & compare CRC generated by PC // Add new row
//dataGridView1.Update(); // Update datagridview
return;
}
//Case for ABUS_RK
if (ByteArrayToHexString(buffer).StartsWith("AA") && ByteArrayToHexString(buffer).Substring(6, 2).StartsWith("12"))
{
table.Rows.Add(row); // Add new row
row["Source"] = string.Format("{0}", "ABUS_RK");
row["System Time"] = DateTime.Now.ToString("HH:mm:ss:fff");
//row["Source"] = ByteArrayToHexString(buffer).Substring(9, 2);
row["T.S Begin"] = ByteArrayToHexString(buffer).Substring(8, 8);
row["T.S End"] = ByteArrayToHexString(buffer).Substring(16, 8);
row["Length"] = ByteArrayToHexString(buffer).Substring(24, 2);
row["Data"] = ByteArrayToHexString(buffer).Substring(26, 2);
row["CRC"] = ByteArrayToHexString(buffer).Substring(28, 2);
row["CRC_PC"] = crc8.ComputeChecksum(buffer);
//table.Rows.Add(row);
//dataGridView1.Update();
return;
}
你好,
我想根据列中的文本数据更改行颜色。假设我的文本为“ABUS_R/L”,我想将整行设为绿色,将“ABUS_RK”整行设为黄色。
我在 for 循环和 if 循环中尝试了以下语法:
dataGridView1.DefaultCellStyle.ForeColor = Color.Red;
然而,它改变了整个表单的颜色,而不是仅仅改变了行的颜色。
那么谁能告诉我我该怎么做呢?
【问题讨论】:
标签: c# asp.net wpfdatagrid