2009년 8월 5일 수요일

DataGridView에서 현재셀값을 취득하는 방법

DataGridView에서 현재셀값은 CurrentCell이라는 프로퍼티로 취득 가능하다

현재셀의 위치확인

[C#]
//현재 셀 값을 표시
Console.WriteLine(datagridviewA.CurrentCell.Value);
//현재 셀의 열 인덱스를 표시
Console.WriteLine(datagridviewA.CurrentCell.ColumnIndex);
//현재 셀의 행 인덱스를 표시
Console.WriteLine(datagridviewA.CurrentCell.RowIndex);
현재 셀의 위치만 획득하고자 한다면 DataGridView.CurrentCellAddress 라는 프로파티를 사용하는게 편리하다.

[C#] Console.WriteLine("현재선택한 셀은,({0}, {1})입니다.",datagridviewA.CurrentCellAddress.X,
datagridviewA.CurrentCellAddress.Y);

현재셀위치변경

[C#] //(0, 0)에 현재셀을 위치하고 싶을때 DataGridView1.CurrentCell = DataGridView1[0, 0];

현재셀에 Null값을 입력하면 초기값인DataGridView.FirstDisplayedCell프로파티의 설정값을 
참조하여셀위치를 정합니다.

댓글 없음:

댓글 쓰기