0
在我的ultragrid中,我有一個Nullable = Disallow的列,表示該字段不能爲空。如果我嘗試將我的列編輯爲空白字符串,則會引發我的CellDataError事件,如我所料。然後,然後,我想在整個對話框中單擊「取消」(單元格仍爲空白),然後再次觸發驗證。如何在取消按鈕單擊UltraGrid時停止單元格驗證
如何在單擊取消按鈕時跳過驗證?
在我的ultragrid中,我有一個Nullable = Disallow的列,表示該字段不能爲空。如果我嘗試將我的列編輯爲空白字符串,則會引發我的CellDataError事件,如我所料。然後,然後,我想在整個對話框中單擊「取消」(單元格仍爲空白),然後再次觸發驗證。如何在取消按鈕單擊UltraGrid時停止單元格驗證
如何在單擊取消按鈕時跳過驗證?
爲了跳過驗證,當單擊取消按鈕時必須允許可爲空的值,然後在更新單元格時再次禁止可以爲空的值。以下是您如何使用代碼實現它。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.ultraGrid1.DataSource = InitializeGridSource();
this.ultraGrid1.DisplayLayout.Bands[0].Columns[0].Nullable = Infragistics.Win.UltraWinGrid.Nullable.Disallow;
this.ultraGrid1.AfterCellUpdate += new CellEventHandler(ultraGrid1_AfterCellUpdate);
this.Deactivate += new EventHandler(Form1_Deactivate);
}
private void ultraGrid1_AfterCellUpdate(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e)
{
this.ultraGrid1.ActiveCell.Column.Nullable = Infragistics.Win.UltraWinGrid.Nullable.Disallow;
}
private void Form1_Deactivate(object sender, EventArgs e)
{
if (this.OwnedForms.Length > 0 && this.OwnedForms[0].Text == "Data Error")
{
this.OwnedForms[0].FormClosing += new FormClosingEventHandler(Form1_FormClosing);
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if ((sender as Form).DialogResult == System.Windows.Forms.DialogResult.Cancel)
{
var activeCell = this.ultraGrid1.ActiveCell;
activeCell.Column.Nullable = Infragistics.Win.UltraWinGrid.Nullable.Automatic;
activeCell.EditorResolved.ExitEditMode(forceExit: true, applyChanges: true);
this.ultraGrid1.UpdateData();
}
}
private DataTable InitializeGridSource(int rows = 7)
{
DataTable newTable = new DataTable("Table1");
newTable.Columns.Add("String Column", typeof(string));
for (int index = 0; index < rows; index++)
{
newTable.Rows.Add(new object[] { "Text " + index });
}
return newTable;
}
}