I have written the following class to build a data grid
textbox column that has the KeyUp and KeyPress events
defined for the TextBox. I also defined the KeyDown event
for testing purposes only. The problem I am having is
that the KeyUp event never fires, while the KeyPress and
KeyDown events do fire. I have defined the events
correctly (I think), so this is leading me to beleive that
this may be a bug. Has anyone had this problem or know if
this is a known bug. I have searched and was not able to
find any information about it. Any help would be greatly
appreiciated.
public class DataGridDigitsTextBoxColumn :
DataGridTextBoxColumn
{
public DataGridDigitsTextBoxColumn
()
: base()
{
this.TextBox.KeyPress +=
new System.Windows.Forms.KeyPressEventHandler
(HandleKeyPress);
this.TextBox.KeyDown +=
new System.Windows.Forms.KeyEventHandler
(this.HandleKeyDown);
this.TextBox.KeyUp += new
System.Windows.Forms.KeyEventHandler(this.HandleKe yUp);
}
private void HandleKeyPress(object
sender, System.Windows.Forms.KeyPressEventArgs e)
{
// TextBox tb = (TextBox)
sender;
//ignore if not digit or
control key
if(!char.IsDigit
(e.KeyChar) && !char.IsControl(e.KeyChar))
{
e.Handled = true;
return;
}
// OnTextChanged(int.Parse
(tb.Text), true);
}
private void HandleKeyUp(object
sender, System.Windows.Forms.KeyEventArgs e)
{
TextBox tb = (TextBox)
sender;
OnTextChanged(int.Parse
(tb.Text), true);
}
private void HandleKeyDown(object
sender, System.Windows.Forms.KeyEventArgs e)
{
MessageBox.Show("The
KeyDownEvewnt fired!");
}
protected override void Dispose
(bool disposing)
{
if(disposing)
{
this.TextBox.KeyPress -= new
System.Windows.Forms.KeyPressEventHandler
(this.HandleKeyPress);
this.TextBox.KeyUp -= new
System.Windows.Forms.KeyEventHandler(this.HandleKe yUp);
}
base.Dispose(disposing);
}
public delegate void
TextChangedEventHandler(object source,
TextChangedEventArgs e);
public class
TextChangedEventArgs : EventArgs
{
public TextChangedEventArgs
(int val, bool boolVal)
{
data = val;
dataChanged =
boolVal;
}
public int data;
public bool dataChanged;
}
public event
TextChangedEventHandler TextChanged;
private void OnTextChanged(int
val, bool boolVal)
{
if(TextChanged != null)
{
TextChanged(this,
new TextChangedEventArgs(val, boolVal));
}
}
}
}
Mike Burkhart
Senior Software Engineer
Itron, Inc.
Spokane, WA