473,394 Members | 1,706 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,394 software developers and data experts.

Keypress event inside datagrid cell

Ok a couple things I've got going: On the DataGrid1_CurrentCellChanged I add a button control to the datagridtextbox. This occurs when a mouse click happens inside the cell or the cursor enters the cell. I'm trying to figure out how to capture the Enter key so to run the buttoncontrol click function. I can get this to work when the datagrid only is activated (by clicking on the whitespace of the grid) but of course it won't work when the cursor is activated. I either need to capture the keypress event while a cell is activated so it can run the button control function or after I add the button control to the datagridtextbox somehow select the whitespace so the datagrid.keypress event will run.
FYI - I'm not sure how to implement this solution or if it will work for what I need: Override ProcessCmdKey

Code:
Expand|Select|Wrap|Line Numbers
  1. Public Sub FormatCellControl()
  2.         'Create the button control to be added and set its properties
  3.         ButtonControl = New Button
  4.         ButtonControl.Cursor = System.Windows.Forms.Cursors.Arrow
  5.         ButtonControl.Dock = DockStyle.Fill
  6.         ButtonControl.SendToBack()
  7.         Dim CurrentColumn As Int16 = DataGrid1.CurrentCell.ColumnNumber
  8.         Select Case CurrentColumn
  9.         Case 2
  10.         DatagridTextBox = CType(DataGrid1.TableStyles(0).GridColumnStyles(2), DataGridTextBoxColumn)
  11.         DatagridTextBox.TextBox.Controls.Add(ButtonControl)
  12.         ButtonControl.BringToFront()
  13. End Sub
  14.  
  15. Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged
  16.     FormatCellControl()
  17. End Sub
  18. Private Sub DataGrid1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles DataGrid1.KeyPress
  19.     If Datagrid1.CurrentCell.ColumnNumber = 2 Then
  20.         ButtonClick()
  21.     End if
  22. End Sub
  23. Private Sub ButtonClick()
  24.     Dim ChildFrm As New Form2()
  25.         ChildFrm.ShowDialog()
  26. End Sub
Sep 27 '06 #1
2 5537
Hi chatelain,
Thanks a lot. your code solved my problem and now I solve urs :)
To get the click event of the button in the cell (that u selects), please add declare the following italic line (pointed by arrow) line as
---> Dim ButtonControl As New Button
ButtonControl.Text = "Path"
ButtonControl.Width = 50
ButtonControl.Cursor = System.Windows.Forms.Cursors.Arrow
ButtonControl.Dock = DockStyle.Right
ButtonControl.SendToBack()
Dim CurrentColumn As Int16 = myDataGrid.CurrentCell.ColumnNumber
Dim DataGridTextBox = CType(myDataGrid.TableStyles(0).GridColumnStyles(5 ), DataGridTextBoxColumn)
DataGridTextBox.TextBox.Controls.Add(ButtonControl )
ButtonControl.BringToFront()

as a public member of the class, as

Public WithEvents ButtonControl As New Button

Now add ur handler as

Private Sub ButtonControl_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonControl.Click
MsgBox("test")
End Sub

Enjoy :)
Regards

Ok a couple things I've got going: On the DataGrid1_CurrentCellChanged I add a button control to the datagridtextbox. This occurs when a mouse click happens inside the cell or the cursor enters the cell. I'm trying to figure out how to capture the Enter key so to run the buttoncontrol click function. I can get this to work when the datagrid only is activated (by clicking on the whitespace of the grid) but of course it won't work when the cursor is activated. I either need to capture the keypress event while a cell is activated so it can run the button control function or after I add the button control to the datagridtextbox somehow select the whitespace so the datagrid.keypress event will run.
FYI - I'm not sure how to implement this solution or if it will work for what I need: Override ProcessCmdKey

Code:
Expand|Select|Wrap|Line Numbers
  1. Public Sub FormatCellControl()
  2.         'Create the button control to be added and set its properties
  3.         ButtonControl = New Button
  4.         ButtonControl.Cursor = System.Windows.Forms.Cursors.Arrow
  5.         ButtonControl.Dock = DockStyle.Fill
  6.         ButtonControl.SendToBack()
  7.         Dim CurrentColumn As Int16 = DataGrid1.CurrentCell.ColumnNumber
  8.         Select Case CurrentColumn
  9.         Case 2
  10.         DatagridTextBox = CType(DataGrid1.TableStyles(0).GridColumnStyles(2), DataGridTextBoxColumn)
  11.         DatagridTextBox.TextBox.Controls.Add(ButtonControl)
  12.         ButtonControl.BringToFront()
  13. End Sub
  14.  
  15. Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged
  16.     FormatCellControl()
  17. End Sub
  18. Private Sub DataGrid1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles DataGrid1.KeyPress
  19.     If Datagrid1.CurrentCell.ColumnNumber = 2 Then
  20.         ButtonClick()
  21.     End if
  22. End Sub
  23. Private Sub ButtonClick()
  24.     Dim ChildFrm As New Form2()
  25.         ChildFrm.ShowDialog()
  26. End Sub
Jul 30 '07 #2
Hi All,
I am using datagrid control in my window application. I am designing the grid by a table and table style to add extra controls in the cells like button and drop down.
Now, I have everything ok, But it want to disable the navigation in the datagrid cells by arrow keys. I dont want to change the cell by the arrows key as the Tab key does.
Is there anybody to help me out.
Thnx in advance.
Mos
Aug 1 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Emerson | last post by:
The following assumes a System.Windows.Forms.DataGrid with a System.Data.DataTable set as the DataSource. I'm programming in C# Here's my scenario I click in a cell on a DataGrid. I enter some...
1
by: Gidi | last post by:
hello how can i make a different keypress event for each coulmn in dataGrid (in C#, windows application) to whom i need to register the event?? thank you...
3
by: Darryn Ross | last post by:
Hi, I am trying to catch the KeyPress event on my datagrid but it isn't working... i have also tried registering the handler with the event like this... dgGLBatch.KeyPress += new...
0
by: LordHog | last post by:
Hello all, I am trying to implement an event handler for the KeyPress event for a cell within a DataGridView control. The obvous starting point from the DataGridView keypress event, but this...
7
by: Girish | last post by:
OK.. phew. Playing with data grids for the past few days has been fun and a huge learning experience.. My problem. I have a requirement to display a gird with a gird. Within the embedded grid,...
4
by: Suzanne | last post by:
Hi all, I'm having problems with datagrids and the currentcellchanged event. My problem is this: I have a datagrid on a form, if the user changes the text in a cell on the datagrid then tries to...
10
by: Tim Frawley | last post by:
I am attempting to detect a Shift+Tab in the KeyPress event for back navigation on a control that doesn't support this method. Does anyone have any ideas how to compare e.KeyChar to a ShiftTab? ...
3
by: Terry Olsen | last post by:
Is there anyway to cause a KeyPress event in a datagrid cell? The only way I get a keypress event is if none of the cells are selected. I was hoping to have the program respond to a certain...
4
by: Roger | last post by:
I have a datagrid and would like to know what even fires when a cell is changed? I want to know when the user changes a cell and moves to the next. I have some code that needs to be done to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.