473,387 Members | 3,781 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Problem with Key events for a DataGridTextBoxColumn

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
Nov 15 '05 #1
0 1570

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Chris Plowman | last post by:
Hi all, I was wondering if anyone can help me with a really annoying problem I have been having. I made a derived datagrid class that will select the row when a user clicks anywhere on a cell...
3
by: clyyy2002 | last post by:
At added two column and more column hereafter,I immediately click del button,the program is no problem. but if i first click the DataGrid columnHeader and then click the del button, i find when...
0
by: Davewadd | last post by:
I'm having an odd problem with a datagrid in a c# program. The program maintains a schedule of jobs that need to be run. As jobs run, the status and next run date/time info are updated in a SQL...
2
by: Lars Netzel | last post by:
I have used a TableStyle to add a ComboBox column in a cell in a datagrid. Now I need to catch the SelectedIndexChanged from the datagrid cell... but I have no clue at all on how to do this! ...
6
by: Ron L | last post by:
I have a dataset whose source is a SQL 2k stored procedure that I am trying to display in a datagrid. This datasource has 4 columns that I am interested in here, a text column and 3 value columns...
4
by: pmclinn | last post by:
Below is the code I'm using to dynamically fill a datagrid from a datatable (fed by an ole connection). Everything is working great except that my users have to click 2 time on the checkbox to...
3
by: Jason Huang | last post by:
Hi, In my C# Windows form project. I am wondering can we manually define the width of a cell in a DataGrid? Thanks for help. Jason
1
by: Stephen Plotnick | last post by:
I have a checkbox in a data grid that does not change it's state until I actually leave the field. I've done this routine several times in other data grids without an issue. I'm using VB.2003. ...
4
LoanB
by: LoanB | last post by:
Hi gang, Im busy writing my firs Windows Mobile 6 Application. - I'm a beginner ok. My first problem: When I run the app through the emulator I get an error: Database file cannot be found. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.