0

各ステートメントのヘルプが必要です。基本的に、ユーザーがセル内の値を編集すると、foreachがこれをデータグリッド内のすべてのセルに適用し、それらすべての値を変更します。foreachステートメントが機能する必要があります。データグリッドを反復処理しますが、編集された選択された行のみを変更しますが、すべての行のカウントを更新しているように見えますが、これは現在の行のみである必要があります

foreach (DataGridViewRow row in dgvDetials.Rows) //loop through each of the results
            {
                string scrapDate, scrapShift, PartCode;
                scrapDate = dtpInspectionDate.Value.ToString("MM/dd/yyyy");
                scrapShift = cbShift.Text;

                PartCode = row.Cells[0].Value.ToString();

                //define each of the counts
                int qtyInspCount = SQLMethods.CountQtyInspTotal(scrapDate, scrapShift, area, PartCode);
                int scrapCount = SQLMethods.CountScrapReworkTotal(scrapDate, scrapShift, area, PartCode, "S");
                int reworkCount = SQLMethods.CountScrapReworkTotal(scrapDate, scrapShift, area, PartCode, "R");

                //populate each of the counts cells
                row.Cells[2].Value = 0;
                row.Cells[5].Value = qtyInspCount;
                row.Cells[3].Value = scrapCount;
                row.Cells[4].Value = reworkCount;
            }
4

2 に答える 2

2

現在の行のみを変更する必要があります。
次に、データグリッド行コレクション全体での長いループを回避する必要があります。

このためだけにCurrentRowプロパティがあります。

if(dgvDetials.CurrentRow != null)
{
    // Reference the current row 
    DataGridViewRow row = dgvDetials.CurrentRow;

    PartCode = row.Cells[0].Value.ToString(); 
    .....
    row.Cells[2].Value = 0; 
    row.Cells[5].Value = qtyInspCount; 
    row.Cells[3].Value = scrapCount; 
    row.Cells[4].Value = reworkCount; 
    .....
}
于 2012-08-23T12:52:18.913 に答える
1

CellValueChangedイベントにバインドするか、選択したGridViewRowを取得する必要があります。

GridViewRow datRow = SomeGridView.SelectedRow;
于 2012-08-23T13:37:45.860 に答える