2012-12-03 2 views
3

DataGridView에서 선택된 행의 값을 가져 와서 함수에 전달하는 프로그램이 있습니다. 그러나 gridView는 비어 있거나 선택된 행을 가질 수 없습니다. 나는 빈 그리드를 처리했지만 행이 선택되었는지를 알 수있는 방법이 있는지 궁금했다. 적어도 하나의 dataGridView 행이 선택되었는지 어떻게 알 수 있습니까? C#

나는이 시도 :

if (Convert.ToInt32(dataGridView1.Rows.Count) > 0) 
{ 
    //It is not empty 
} 
int c = dataGridView1.SelectedRows.Count(); //this line gives me an error 
if (c>0) 
{ 
    //there is a row selected 
} 

나는이 문제를 해결하는 방법을 알고 있습니까?를

+0

신경 끄시을, 나는 문제 파악 어디에 두 번째 "백작"감사 후 괄호. –

답변

5

단순히 "Count"키워드 다음에 괄호를 제거하십시오. 그것은 다음과 같아야합니다

if (Convert.ToInt32(dataGridView1.Rows.Count) > 0) 
{ 
    //It is not empty 
} 
int c = dataGridView1.SelectedRows.Count; //remove parenthesis here 
if (c>0) 
{ 
    //there is a row selected 
} 
2
if (dataGridView1.Rows.Count > 0 && dataGridView1.SelectedRows.Count > 0) { 
    ...... 
} 
관련 문제