C#

DataGridView 에서 Cells 값 Null/Empty 체크하기

by kay posted Jul 22, 2013
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

크게 작게 위로 아래로 댓글로 가기 인쇄

Null / Empty 값일 경우 체크하기


int i = dataGridView1.Rows.Count;
for (int j = 0; j < i; j++)
{
	string strCol2 = null;
	string strCol3 = null;
	if (dataGridView1.Rows[j].Cells[1].Value == null || dataGridView1.Rows[j].Cells[1].Value == DBNull.Value )
		strCol2 = "----";
	else
		strCol2 = dataGridView1.Rows[j].Cells[1].Value.ToString();

	if (dataGridView1.Rows[j].Cells[2].Value == null || dataGridView1.Rows[j].Cells[2].Value == DBNull.Value )
		strCol3 = "----";
	else
		strCol3 = dataGridView1.Rows[j].Cells[2].Value.ToString();
}