验证DataGridView单元格的值

private void gridPurchaseOrderDetail_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            if (gridPurchaseOrderDetail.Columns[e.ColumnIndex].CellType.ToString().Contains("TextBox")) 
            {
                if (Common.GetDecimal(e.FormattedValue) < 0) 
                {
                    MessageBox.Show("请检查输入数据的格式", "消息", MessageBoxButtons.OK);
                    e.Cancel = true;
                }
            }
        }

 

你可能感兴趣的:(datagridview)