dataGridRows.Cells[1]
にはどれくらいの数字がありますか0
があります。このコードをdataGridView1_RowPostPaint
イベントに追加しました。データグリッドセル値がカウントされます
private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
int count=0;
if (dataGridView1.Rows.Count > 1)
foreach (DataGridViewRow row in dataGridView1.Rows)
{
count++;
foreach (DataGridViewCell cell in row.Cells)
{
if (Convert.ToInt32(cell) == 0)
{
label3.Text = count.ToString();
}
}
}
}
私もこれで試してみました:wchichの
private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
int count=0;
foreach (DataGridViewRow row in dataGridView1.Rows)
{
count++;
foreach (DataGridViewCell cell in row.Cells)
{
if (cell.Value.ToString() == "0")
{
label3.Text = count.ToString();
}
}
}
}
いずれも正常に動作しません。最初のものは全く数えられません。 2番目のコードで、私にエラーが発生しましたAn exception of type 'System.NullReferenceException' occurred in skraper.exe but was not handled in user code
私にそれを手伝ってもらえますか?
すべてのセルに数字「0」が何回表示されているか知りたいですか? – MasterXD
セルの内容として「0」しかないセルがいくつあるか知りたい。 – audiophonic