2011-09-19 4 views
0

나는 myDataGridViewCell가 DataGridViewCheckBoxCellDataGridViewCell의 유형을 테스트하려면 어떻게해야합니까?

if(myDataGridViewCell.ValueType is DataGridViewCheckBoxCell) ... 

있는지 여부를 테스트하려고하지만이 경고 제공 :

주어진 표현이 결코 제공 'System.Windows.Forms.DataGridViewCheckBoxCell'의 없음)

을 입력을

DataGridViewCell의 유형을 어떻게 테스트 할 수 있습니까?

답변

2

ValueType은 셀이 보유하는 데이터 값 유형입니다. 그것은 당신이 원하는 것이 아닙니다.

셀 itslelf의 유형을 테스트하려면, 단지 수행

if (myDataGridViewCell is DataGridViewCheckBoxCell) 
... 

또는

if (myDataGridViewCheckBoxCell != null && 
    myDataGridViewCheckBoxCell.GetType() == typeof(DataGridViewCheckBoxCell)) 
    ... 

( DataGridViewCheckBoxCell 및 모든 하위 유형에 대한 true가됩니다) (마찬가지 될 것입니다 DataGridViewCheckBoxCell 만 해당).

+0

Charles and SLacks - 감사합니다. – ChrisJJ

2
if (myDataGridViewCell is DataGridViewCheckBoxCell) 

귀하의 코드는 ValueType property의 값이 DataGridViewCheckBoxCell로 변환 여부를 확인하고 있습니다.
ValueType은 항상 System.Type 인스턴스를 보유하므로 절대 컴파일러가 아니기 때문에 DataGridViewCheckBoxCell이 아니므로 컴파일러에서 경고를 표시합니다.

관련 문제