如题

解决方案 »

  1.   

    winform
    还是webformwebform有验证控件C# 複製程式碼//Handle column changing events on the Customers table
    private void Customers_ColumnChanging(object sender, System.Data.DataColumnChangeEventArgs e) {   //Only check for errors in the Product column
       if (e.Column.ColumnName.Equals("Product")) {      //Do not allow "Automobile" as a product
          if (e.ProposedValue.Equals("Automobile")) {
             object badValue = e.ProposedValue;
             e.ProposedValue = "Bad Data";
             e.Row.RowError = "The Product column contains an error";
             e.Row.SetColumnError(e.Column, "Product cannot be " + badValue);
          }
       }
    }
      

  2.   

    微软官方答案http://msdn.microsoft.com/zh-tw/library/0ye0dkkw(VS.80).aspxHOW TO:使用 Windows Form DataGrid 控制項驗證輸入