To微软专家,MVP,用过DataTable_RowFocusChanging()判断数据有效性的帮我看看,谢谢!
好运 2003-08-18 07:01:55 BindDataGrid()
{
---
OrderDetail.RowChanging+=new System.Data.DataRowChangeEventHandler(RowCheck);
---
}
private void RowCheck(object sender,DataRowChangeEventArgs e)
{
try
{
DataTable dt=(DataTable)sender;
DataRow SourceRow=e.Row;
string FashionID=SourceRow.ItemArray.GetValue(0).ToString();
string Qty=SourceRow.ItemArray.GetValue(6).ToString();
if(Sytech.Sungod.PlanSystem.PlanSystemLib.Util.CheckValidate.CheckFashion(frmPortal.m_DataManage,FashionID)==false)
{
throw new Exception("产品编号无效!");
}
try
{
int OrderQty=int.Parse(Qty);
}
catch(System.FormatException)
{
throw new Exception("订单数量无效!");
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message,"错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}用这种方法检验数据的有效性,Winform的DataGrid出现了超怪的现象,DataGrid控件变成了一个白块,中间是红色的对角线,有兴趣的测试一下。