Can not do this why it is not, there is sample code here:
public form 1 () {Initialization (); // Create DataGrid DataGrid DG = New DataGrid (); Dg.Parent = This; Dg.Location = New point (10, 10); Dg.Size = New system. Drawing. Size (300, 200); // List people list & lt; Person & gt; People = Lawful people (f); // Bind List Binding List & lt; Person & gt; Bl_people = new binding list & lt; Person & gt; (People); Dg.DataSource = bl_people; // format grid digitable style Clear (); Data GridTableStyle DGTS = NewData GridTableStyle (); Dgts.MappingName = bl_people.GetType (). Name; Dgts.ReadOnly = True; DataGradeTextBoxColationCol_name = New DataGridTextBoxColumn (); Col_name.MappingName = "name"; Col_name.HeaderText = "name"; Dgts.GridColumnStyles.Add (COL_NAME); Data GridTextbox ColumnCall_Height = New DataGridTextBox Column (); Col_height.MappingName = "Height"; Col_height.HeaderText = "Height (cm)"; Dgts.GridColumnStyles.Add (col_height); Dg.TableStyles.Add (dgts); // Cloud Events col_name.TextBox.KeyDown + = New KeyEventHandler (TextBox_KeyDown); Col_name.TextBox.KeyUp + = New KeyEventHandler (TextBox_KeyUp); }
Deal with incident methods:
Zero TextBox_KeyUp (Object Sender, KeyEventArgs E) {// KeyUp Debug.WriteLine ("Do something on KeyUp! "); } Zero TextBox_KeyDown (Object Sender, KeyEventArgs E) {// Do something on Keydown Debug. WrightLine ("Keydown!"); }}
After pressing a value from the Name column, DataGridTextBoxColumn is focused whenever I press the key KeyDown event is removed but nothing happens for KeyUp event, even when KeyDown event is not subscribed to
I really need a cape event, the keydown is not fit in my purpose and I can not just switch to DataGridView This code will be used with compact structure :(
How can I solve it?
DataGrid control "Swallow" is a habit of events of some keyboards It's their internal processes (I believe they can take action by different grid cells Mr. is) and they will not control the other because the event "before the bubble itself has been consumed."
There are two different ways to do this. Basically you need to set this data grid hit form before pausing the event, then pre-process and decide that you also want to pass the data grid to the event.
Do the following to create a "universal filter" in your application. If you are following the Dispatcher pattern and you probably need to root the key, then you will do stroke to one of the many different controls:
In the manufacturer of your form:
this.KeyPreview = true; Application.AddMessageFilter (this);
Override this method in your form If this method gives "truth" then the event will be consumed and will not be sent to any other controls. If this method gives, then the "wrong" event will normally bubble through all the controls.
// This is the only way to prevent buttons, check boxes, and datagrids from up and down arrow processing Const Int WM_KEYDOWN = 0x100; Const int WM_KEYUP = 0x101; Public bool PreFilterMessage (reference message m) hold {{if (m.msg == WM_KEYDOWN) handle the event here and return true else if (m.msg == WM_KEYUP) handle the event here // and true} return // try { } return false; } return false; }
I wrote / wrote this about 10 years ago, so there are other / better ways to do this, but it worked for me and I have not been made a custom implementation It works for any control.
Another technique I found in an MSDN article is written for VB, but it should be translated very easily to C #:
Here the basic data is to override the grid subclass and ProcessCmdKey
method <. / P>
No comments:
Post a Comment