2017-08-23 17 views
0

私の超挑戦では、Nullable = Disallowを持つ列があります。つまり、フィールドを空白にすることはできません。私の列を空の文字列に編集しようとすると、期待どおりにCellDataErrorイベントが発生します。しかし、私は私の全体のダイアログ(セルはまだ空白)でキャンセルを押すと、これは再び検証をトリガします。UltraGridでキャンセルボタンをクリックしたときにセルの検証を停止する方法

キャンセルボタンをクリックしたときの検証をスキップするにはどうすればよいですか?

答えて

0

検証をスキップするには、キャンセルボタンをクリックしたときにnull値を許可してから、セルが更新されたときにnull値を再度許可しないでください。コードでこれを実現する方法は次のとおりです。

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; 
    } 
} 
関連する問題