Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ColumnChanging event not firing in DataGrid

Status
Not open for further replies.

goneWildCoder

Programmer
May 26, 2004
20
US
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;
}

}

...
..
.

}
 
I think that depends on how it's fired the event inside a cell. The cell could expect a non null data to fire the event.

________
George, M
Searches(faq333-4906),Carts(faq333-4911)
 
ColumnChanging event does not fire when the value in a cell is not changed....
 
I don't know whether I understood you correctly, are you trying to find out an event which will fire everytime user "TAB" through a any field. If so you are using the wrong event. ColumnChanging occurs only when a value in the datacolumn is changed. You should add an OnKeyPress event handler to the grid and then should trap the "TAB" key there.

-Kris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top