PC Review


Reply
Thread Tools Rate Thread

Detecting keypresses in a Datagrid cell

 
 
robert_rowe
Guest
Posts: n/a
 
      12th May 2004
Does anyone know how to detect keypresses in a Datagrid cell? The
Keypress event ofthe datagrid doesn't fire if you are in a cell.
Neither does KeyUp & KeyDown. I've tried hooking in to the
DataGridCell events but it doesn't have the keypress event.

Robert

 
Reply With Quote
 
 
 
 
Konrad L. M. Rudolph
Guest
Posts: n/a
 
      12th May 2004
robert_rowe wrote:

> Does anyone know how to detect keypresses in a Datagrid cell? The
> Keypress event ofthe datagrid doesn't fire if you are in a cell.
> Neither does KeyUp & KeyDown. I've tried hooking in to the
> DataGridCell events but it doesn't have the keypress event.


Guess:
set the KeyPreview property of the parent form to "True" and use the
KeyPress event of the form instead.

--
Konrad -
http://madrat.net/
 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      12th May 2004
* (E-Mail Removed)lid (robert_rowe) scripsit:
> Does anyone know how to detect keypresses in a Datagrid cell? The
> Keypress event ofthe datagrid doesn't fire if you are in a cell.
> Neither does KeyUp & KeyDown. I've tried hooking in to the
> DataGridCell events but it doesn't have the keypress event.


You will have to take the 'KeyPress' event of the cell. In order to do
that, you will have to derive a class from 'DataGridColumnStyle' and
assign your own 'GridColumnStyle' of your 'TableStyle'. Then you add a
handler to the 'KeyPress' event of the class created in the last step.

Source code (taken from a post by Peter Fleischer):

\\\
....
Me.DataGrid1.TableStyles.Clear()
Dim dgts As New DataGridTableStyle
dgts.MappingName = "Tab1"
Me.DataGrid1.TableStyles.Add(dgts)
Dim myTextBoxColumn As DataGridTextBoxColumn = _
DataGrid1.TableStyles("Tab1").GridColumnStyles("Feld2")
Dim dgtb As DataGridTextBox = _
CType(myTextBoxColumn.TextBox, DataGridTextBox)
AddHandler dgtb.KeyPress, AddressOf meineTastenPresse
....

Private Sub meineTastenPresse(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyPressEventArgs)
Debug.WriteLine("Gedrückt: " & Asc(e.KeyChar).ToString)
End Sub
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      13th May 2004
Hi Herfried,

Is there a reason why you use CType instead of DirectCast in this sample?

Cor


 
Reply With Quote
 
robert_rowe
Guest
Posts: n/a
 
      13th May 2004
It worked great. Thanks.

 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      13th May 2004
* "Cor Ligthert" <(E-Mail Removed)> scripsit:
> Is there a reason why you use CType instead of DirectCast in this sample?


It's Peter Fleischer's example, not mine ;-). I didn't change anything
in the code.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      13th May 2004
So why his and not mine?

I did not copied mine from his.

Cor


 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      13th May 2004
* "Cor Ligthert" <(E-Mail Removed)> scripsit:
> So why his and not mine?
>
> I did not copied mine from his.


?!?

<URL:http://www.google.de/groups?selm=bmh3k0%24mhcuo%241%40ID-117757.news.uni-berlin.de>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      13th May 2004
Hi Herfried,

I mean this one that I made some days ago for OHM, this sample is complete
and in the line of this newsgroup, I did not know there exist already one.
(Do not cry there are also with HKW in it).

http://groups.google.com/groups?selm...TNGP12.phx.gbl

It is valuechanged in stead of keypresses of course because you says always
that that is better
(not serious)

And that is the reason I saw your CType because I had used it there, I have
changed it now in my snippets in my HKW database, which is by the way a
tooltip sample in a datagrid that I changed for OHM.

Cor


 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      13th May 2004
* Cor Ligthert:
>So why his and not mine?
>
>I did not copied mine from his.


I didn't see that you posted a sample, and I would have had to change
it.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Detecting the active datagrid Hans Fehlow Microsoft VB .NET 1 19th Jul 2007 10:14 PM
Detecting the active datagrid Hans Fehlow Microsoft Dot NET Framework 3 19th Jul 2007 09:37 PM
Detecting value change in a datagrid cell =?Utf-8?B?TWlrZQ==?= Microsoft Dot NET 2 1st Feb 2007 04:24 AM
Detecting Changes in Datagrid? Moogy Microsoft ADO .NET 14 17th Feb 2004 09:44 PM
DataGrid - Detecting which cell was clicked Randy Microsoft C# .NET 3 17th Sep 2003 03:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:45 AM.