ColumnChanging event on Dataset
-
Hi all, I have a ColumnChanging event attached to a dataset to perform validations. For some reason unknown to me, the event does not get fired when the user presses the 'tab' key with a null cell. I am trying to make sure that no cell is null. When no value is entered in a cell, and the column is changed, I want the ColumnChanging event to capture it and throw a messagebox to the user. Please help. Here is what I have --> private void Division_ColumnChanging(object sender, System.Data.DataColumnChangeEventArgs e) { ... .. . if ( (e.Column.ColumnName.Equals("Div_Code")) || (e.Column.ColumnName.Equals("Div_Name")) ) { if(e.ProposedValue.ToString().Length == 0) { MessageBox.Show("Column " + cs.HeaderText + " cannot be null.", "SPIRIT2 - Error", MessageBoxButtons.OK, MessageBoxIcon.Error); dataGrid1.CurrentCell = (DataGridCell) sender; } } ... .. . }
-
Hi all, I have a ColumnChanging event attached to a dataset to perform validations. For some reason unknown to me, the event does not get fired when the user presses the 'tab' key with a null cell. I am trying to make sure that no cell is null. When no value is entered in a cell, and the column is changed, I want the ColumnChanging event to capture it and throw a messagebox to the user. Please help. Here is what I have --> private void Division_ColumnChanging(object sender, System.Data.DataColumnChangeEventArgs e) { ... .. . if ( (e.Column.ColumnName.Equals("Div_Code")) || (e.Column.ColumnName.Equals("Div_Name")) ) { if(e.ProposedValue.ToString().Length == 0) { MessageBox.Show("Column " + cs.HeaderText + " cannot be null.", "SPIRIT2 - Error", MessageBoxButtons.OK, MessageBoxIcon.Error); dataGrid1.CurrentCell = (DataGridCell) sender; } } ... .. . }
Hi, Typically in the empty column of a table, the value "(null)" is entered by default(for a data grid atleast) and that is probably why the null case is not being detected. You will probably need to put in a break point to see if the value being returned is indeeed "NULL" instead of "" like you expect. I haven't tested this myslef so I could be way off. Hope this helps.