달력

52024  이전 다음

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

C#에서 DataGridViewRow 를 복사하려는데 오류가 자꾸 발생한다.

분명 설명에는 DataGridView.Rows.Add(DataGridViewRow )가 있다..
그런데 왜 오류가 날까....

이유는 Row에 값을 넣는 방법이 문제 였다 ㅡㅡ;;

대충 해결 방법

DataGridView dgv = new DataGridView();
...  (dgv에 특정 데이터를 집어 넣은 상태);

DataGridView dGrid  = new DataGridView();
DataGridViewRow dgvRow = new DataGridViewRow();
dgvRow = CloneWithValues(dgv.Rows[i]);

dGrid.Rows.Add(dgvRow); 
public DataGridViewRow CloneWithValues(DataGridViewRow row);
{
      DataGridViewRow clonedRow = (DataGridViewRow)row.Clone();
      for (Int32 index = 0; index < row.Cells.Count; index++)
      {
        clonedRow.Cells[index].Value = row.Cells[index].Value;
      }
      return clonedRow;
}

함수로 만들었지만.. 문제는 Cell에 값을 넣는게 문제 였다..
Row를 만들고 셀에 값을 잘 넣어주면 해결 되더라능 ㅡㅡ;

Posted by SadDev
|