C
coconet
I have a .NET 2.0 DataTable with a ColumnChanging event. There is code
in the event that tests ProposedValue and if it is "a" then the value
I want in the column should be "1". The column is Type Int32.
Main program (C#) flow is
string teststring = "a";
DataRow datarow = mytable.NewRow();
mytable.Rows.Add(datarow);
datarow["IntColumn"] = teststring;
Event code snippet is
if ( e.Column.ColumnName == "IntColumn" )
{
if ( e.ProposedValue.ToString() == "a" )
{
e.Row[e.Column] = 1;
}
}
The data is first properly set to 1, then the ColumnChaning event
fires again but the "if" conditional fails so control goes back to the
main program/method. Then the ' datarow["IntColumn"] = teststring;'
line runs and an Exception is thrown because a string is going into
the column again.
I would like to keep my logic code in the ColumnChanging event to
convert the input string to an int where I need it. What is the best
way to make that happen? And how can I make the event only fire once?
Thanks.
in the event that tests ProposedValue and if it is "a" then the value
I want in the column should be "1". The column is Type Int32.
Main program (C#) flow is
string teststring = "a";
DataRow datarow = mytable.NewRow();
mytable.Rows.Add(datarow);
datarow["IntColumn"] = teststring;
Event code snippet is
if ( e.Column.ColumnName == "IntColumn" )
{
if ( e.ProposedValue.ToString() == "a" )
{
e.Row[e.Column] = 1;
}
}
The data is first properly set to 1, then the ColumnChaning event
fires again but the "if" conditional fails so control goes back to the
main program/method. Then the ' datarow["IntColumn"] = teststring;'
line runs and an Exception is thrown because a string is going into
the column again.
I would like to keep my logic code in the ColumnChanging event to
convert the input string to an int where I need it. What is the best
way to make that happen? And how can I make the event only fire once?
Thanks.