111,098
社区成员




System.Windows.Forms.DataGridView dataGridView1 = new System.Windows.Forms.DataGridView();
int ReceiveData_Length = (new Random(DateTime.Now.Millisecond)).Next(1000);//我就不做tcp了我生成一个随机长度吧
int left = 0;
for (int i = 0; i < Math.DivRem(ReceiveData_Length, 8,out left)+1; i++)//先整除8并求余数确定一个总列数
{
for (int j = 0; j < 8; j++)
{
if (i * 8 + j < ReceiveData_Length)
{
dataGridView1.Rows[i].Cells[j].Value = i * 8 + j;//在读取范围内的就赋值,你的赋值当然是ReceiveData[i * 8 + j]
}
else
{
dataGridView1.Rows[i].Cells[j].Value = 0;//如果超出范围的部分就给个0或者其他值
}
}
}
//这样就可以实现每行8个数据了。
int index = this.dataGridView1.Rows.Add();
for (int i = 0; i < ReceiveData.Length; i++)
{
this.dataGridView1.Rows[index].Cells[i].Value = ReceiveData[i];
}