T
Timothy Graves
I have a quick (pun intended) question for the guru's out there.
I have a piece of code where I am validating the input of chancters
into a cell in a datagrid. I am using the keypressed event to get the
charcter that the user typed and then allowing it to be passed to the
cell. Now here is the tricked part, I am also validating the values
(max and min) so that the user does not input a invalid number (out of
range ex. byte != 256).
Here is my code.
//////START CODE//////
DateTime begin = DateTime.Now;
try
{
System.Convert.ToByte(tableDataGrid.Controls[tableDataGrid.CurrentCell.ColumnNumber
+ 2].Text + e.KeyChar);
//This takes the current value in the cell (before editing has
finished)
//and appends the current pressed key and tries to convert it to a
byte
e.Handled = false;
//if no exception is throwed then it is allowed to be sent to the
cell
}
catch(System.OverflowException)
{
e.Handled = true;
//if an exception does occur then it is not passed
}
DateTime end = DateTime.Now;
info.Text = Convert.ToString(end - begin);
//just a multi line text box that I used for debugging and performance
//////END CODE//////
The reason that I am asking this is that exceptions are costly
performance wise. This code in the block takes 2.2656250 seconds to
be performed when an exception is thrown. But without one the ode
executes too quickly to be timed (sp?).
Do ya'll see any way to increase the speed of the exception or code.
I'm up for anythng really.
Thanks all
Tim
I have a piece of code where I am validating the input of chancters
into a cell in a datagrid. I am using the keypressed event to get the
charcter that the user typed and then allowing it to be passed to the
cell. Now here is the tricked part, I am also validating the values
(max and min) so that the user does not input a invalid number (out of
range ex. byte != 256).
Here is my code.
//////START CODE//////
DateTime begin = DateTime.Now;
try
{
System.Convert.ToByte(tableDataGrid.Controls[tableDataGrid.CurrentCell.ColumnNumber
+ 2].Text + e.KeyChar);
//This takes the current value in the cell (before editing has
finished)
//and appends the current pressed key and tries to convert it to a
byte
e.Handled = false;
//if no exception is throwed then it is allowed to be sent to the
cell
}
catch(System.OverflowException)
{
e.Handled = true;
//if an exception does occur then it is not passed
}
DateTime end = DateTime.Now;
info.Text = Convert.ToString(end - begin);
//just a multi line text box that I used for debugging and performance
//////END CODE//////
The reason that I am asking this is that exceptions are costly
performance wise. This code in the block takes 2.2656250 seconds to
be performed when an exception is thrown. But without one the ode
executes too quickly to be timed (sp?).
Do ya'll see any way to increase the speed of the exception or code.
I'm up for anythng really.
Thanks all
Tim