저는 C#으로 Windows Form 응용 프로그램을 작성 중입니다.필터링 된 DataGridView를 DataRow []에 할당하여 null 값을 지정합니다 (필터 결과 있음)
양식을 추가/삭제할 수있는 DataGridView
입니다. 입력란은 편집 가능 Qty
열이며 그 다음 Save
버튼입니다. Save
클릭하면
, 나는 다른 절약을 진행, 목록에 0.00 Qty
이다, 0.00 Qty
의 DataGridView
항목을 필터링 한 후 /이 있음을 사용자에게 통지합니다.
DataRow[] result = (enrollmedsDataGridView.DataSource as DataTable).Select("Qty = 0.00 OR Qty = 0");
:
이
private void SaveBtn_Click(object sender, EventArgs e)
{
if (isWithZeroQty() == true)
{
MessageBox.Show("Please check Quantity","System Alert",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
else
{
// Will do the saving..
}
}
private bool isWithZeroQty()
{
DataRow[] result = (enrollmedsDataGridView.DataSource as DataTable).Select("Qty = 0.00 OR Qty = 0");
if (result.Count() > 0)
{ return true; }
else
{ return false; }
}
내 문제가 NullReferenceException
이 줄에 발생했습니다 :
내가 양식에 코드를 아래이 있습니다 (저장을 클릭하기 전에 양식의 스크린 샷 참조)
추가 조사를 위해 DataGridView를 캐스팅 할 때 DataTable (enrollmedsDataGridView.DataSource as DataTable)
으로 NullReferenceException이 발생합니다.
DataGridView가 BindingSource에 대한 DataBounded이기 때문에 그렇습니까?
그렇다면 어떻게 해결할 수 있습니까?
도움을 미리 감사드립니다.