2017-10-02 1 views
0

dgv1dgv2이라는 두 개의 datagridview를 가지므로 DataGridview의 각 행은 일부 ID로 고유합니다. 내가 ID, Quantity, Price & Total 필드를 가지고 있다고 가정 해보십시오.두 DataGridview 셀 사이의 값

우선 dgv1의 모든 값을 dgv2으로 복사합니다. 그 후에 dgv2의 수량 값을 변경하고있는 경우 dgv2의 수량이 특정 ID의 수량 인 dgv1보다 큰 경우 값을 변경해서는 안되며 메시지 또는 이와 비슷한 것을 표시해야합니다.

희망 사항은 명확하게 아래에 작동 코드가 설명되어 있습니다. 그것은 복사, 편집, 곱하기를 위해 잘 작동하지만 datagridview 수량 값을 비교하는 데 도움이 필요합니다.

private void btnCopyTo_Click(object sender, EventArgs e) 
    { 
     foreach (DataGridViewRow item in dataGridView1.Rows) 
     { 
      if ((bool)item.Cells[0].Value == true) 
      { 
       int n = dataGridView3.Rows.Add(); 

       dataGridView3.Rows[n].Cells[0].Value = item.Cells[0].Value.ToString(); 
       dataGridView3.Rows[n].Cells[1].Value = item.Cells[1].Value.ToString(); 
       dataGridView3.Rows[n].Cells[2].Value = item.Cells[2].Value.ToString(); 
       dataGridView3.Rows[n].Cells[3].Value = item.Cells[3].Value.ToString(); 

      } 
     }  
    } 

    private void dataGridView3_CellEndEdit(object sender, DataGridViewCellEventArgs e) 
    { 
     foreach (DataGridViewRow row in dataGridView3.Rows) 
     { 
      row.Cells[dataGridView3.Columns[3].Index].Value = (Convert.ToDouble(row.Cells[dataGridView3.Columns[2].Index].Value) * Convert.ToDouble(row.Cells[dataGridView3.Columns[1].Index].Value)); 
     } 
    } 
+1

어디 비교 코드입니까? 어떻게 작동하지 않습니까? – BugFinder

답변

0

당신의 평균 ?? 나는 명확하게 이해하지 못한다.

private void CompareData() 
    { 
     for (int i = dataGridView1.RowCount - 1; i >= 0; i--) 
     { 
      for (int j = 0; j < dataGridView3.RowCount - 1; j++) 
      { 
       if(Convert.ToDouble(dataGridView1.Rows[i].Cells[1].Value.ToString()) >= Convert.ToDouble(dataGridView3.Rows[j].Cells[1].Value.ToString())) 
       { 
        //handle 

       } 
      } 
     } 

    }