Datagridview - 删除空单元格C#

时间:2017-12-06 11:43:59

标签: c# datagridview

private void button7_Click(object sender, EventArgs e)
{
    if (dataGridView2.RowCount == 1)
    {
        dataGridView2.Rows.Add(11);
    }

    for (uint i = 0; i < 12; i++)
    {
        string Name = PS3.Extension.ReadString(0x1234567+ i * 0x123),
        NPID = PS3.Extension.ReadString(0x1234567 + (i * 0x123)),
        XUID = BitConverter.ToString(PS3.Extension.ReadBytes(0x1234567 + (i * 0x123), 8));
        dataGridView2[0, Convert.ToInt32(i)].Value = Name;
        dataGridView2[1, Convert.ToInt32(i)].Value = NP;
        dataGridView2[2, Convert.ToInt32(i)].Value = XP;
    }

    for (int i = dataGridView2.Rows.Count - 1; i >= 0; i--)
    {
        DataGridViewRow dataGridViewRow = dataGridView2.Rows[i];

        foreach (DataGridViewCell cell in dataGridViewRow.Cells)
        {
            string value = cell.Value as string;

            if (string.IsNullOrEmpty(value))
            {
                if (!dataGridViewRow.IsNewRow)
                {
                    dataGridView2.Rows.Remove(dataGridViewRow);
                }
            }
        }
    }
}

我试图删除所有未使用的单元格,它会删除除了其中一个之外的所有单元格:

enter image description here

其中00-00-00-00-00的那个不会。谁知道为什么?

0 个答案:

没有答案