how to trap backspace in listview?

P

Peter Kellner

I have a listview on my smartphone and I can trap the dial number keys
with the event:

this.listViewCategories.KeyPress += new
System.Windows.Forms.KeyPressEventHandler
(this.listViewCategories_KeyPress);

When I press the backspace, it takes me out of the application. I want
similar behavior to how the contact manager works where you can press
numbers on the keypad and backspace to untype them.

Thanks for any tips on this
 
P

peter

I found the section at the bottom on keys and backspace. It suggests I
trap with keypress which is what I am doing but those lines never get
processed when I set my debugger to stop there. (just with the
backspace). It's a bit lengthy, but I've pasted the simplest code I
can to make this example. Thanks for any help on this. (I tried
stopping in the keypress event of the form also but that didn't hep
either)

Stuck, -Peter

public class Formtest : System.Windows.Forms.Form
{
private ListView listView1;
/// <summary>
/// Main menu for the form.
/// </summary>
private System.Windows.Forms.MainMenu mainMenu1;

public Formtest()
{
InitializeComponent();
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.listView1 = new System.Windows.Forms.ListView();
//
// listView1
//
this.listView1.Location = new System.Drawing.Point(17, 15);
this.listView1.Size = new System.Drawing.Size(140, 138);
this.listView1.KeyPress += new
System.Windows.Forms.KeyPressEventHandler(this.listView1_KeyPress);
//
// Formtest
//
this.ClientSize = new System.Drawing.Size(176, 180);
this.Controls.Add(this.listView1);
this.Menu = this.mainMenu1;
this.Text = "Formtest";
this.KeyPress += new
System.Windows.Forms.KeyPressEventHandler(this.Formtest_KeyPress);

}

#endregion

private void listView1_KeyPress(object sender,
KeyPressEventArgs e)
{
// Set Debug Stop
}

private void Formtest_KeyPress(object sender, KeyPressEventArgs
e)
{
// Set Debug Stop
}




}
 
D

Daniel Moth

Actually, what I should have replied to you is: don't try to trap the back
key since it violates the guidelines. If you need to control user entry and
use the back button as delete, then use a textbox.

Now, if you look at the sample I pointed to, the code applies to a Form
(with no controls on it). So, from what you say, the listview is not capable
of handling the back key (sorry I cannot test that right now). Since there
is no KeyPreview property on the Form in v1.0 of netcf, I can't see an out
of the box way of doing this.

And as I am about to post this I see Sergey has created an example for you

Cheers
Daniel
 
P

Peter Kellner

This followup was posted to
microsoft.public.dotnet.framework.compactframework

I've written for you the example how to trap the Back key for Smartphones:
http://www.sergeybogdanov.com/samples/SPBackCapturing.zip

HTH

Thanks Much for the sample. I've tried running it in both vs2003 and
vs2005. In vs2003 (which is not what I'm using for this prototype BTW)
the project hangs when it opens. My VS2003 never worked correctly with
the compact projects anyway so I am not to worried about that.

In vs2005, for some reason it will not resolve IMessageFilter even
though I see it in System.Windows.Forms. Also, I'm assuming that the
using OpenNETCF.Windows.Forms; is unnecessary? I've never done anything
with importing dll's in .net so I'm glad to be learning this.

Thanks much for your help.

Peter Kellner
http://peterkellner.net
 
P

Peter Kellner

This followup was posted to
microsoft.public.dotnet.framework.compactframework

Actually, what I should have replied to you is: don't try to trap the back
key since it violates the guidelines.
...
And as I am about to post this I see Sergey has created an example for you

Cheers
Daniel

Daniel,

First, I'm flattered to have two experts helping me on this Sunday.
Thank you very much for your comments.

Second, When I'm new in a framework (like I am here) I always try to use
standard applications as my guide. In this case, I want to do something
very similar to how the built in app Contact Manger works for searching.
They use the backspace to "undo" search letters you have already typed.
Is that a violation of the guidelines?

So, assuming it is, I'm trying to go down the path of capturing the left
rocker to undo a typed character. How can I trap that in a listview.
It does not seem to get passed to the keypress event.

Thanks,


Peter Kellner
http://peterkellner.net
 
D

Daniel Moth

The contacts is probably using a custom control. One of the links at the
bottom of my blog entry goes to an msdn article that shows you how to do
that.

If you are using VS2005 with CF 2.0 you can use the Form.KeyPreview property
to catch key events for all controls on your form. A quick test proved that
to be the case for KeyDown so try that...

Cheers
Daniel
 
S

Sergey Bogdanov

I haven't tested it for VS2005 but for compiling it for VS2003 you
should install OpenNETCF SDF [1] before. Since SDF installation only
works for VS2003 you should manually copy OpenNETCF*.dll from
"C:\Program Files\Microsoft Visual Studio .NET
2003\CompactFrameworkSDK\v1.0.5000\Windows CE\Smartphone"

to

"C:\Program Files\Microsoft Visual Studio
8\SmartDevices\SDK\CompactFramework\1.0\WindowsCE\"

[1]
http://www.opennetcf.org/PermaLink.aspx?guid=3a013afd-791e-45ef-802a-4c1dbe1cfef9
 
P

Peter Kellner

This followup was posted to
microsoft.public.dotnet.framework.compactframework

The contacts is probably using a custom control. One of the links at the
bottom of my blog entry goes to an msdn article that shows you how to do
that.

If you are using VS2005 with CF 2.0 you can use the Form.KeyPreview property
to catch key events for all controls on your form. A quick test proved that
to be the case for KeyDown so try that...

I haven't been able to install CF 2.0. I even tried reloading XP from
scratch. I'm using a dell portable and each time I try, it hangs near
the end of the install and just doesn't finish. Shows 100% but never
finishes. Any ideas or every heard of anyone else with the problem? I
emailed Larry at MS and he hadn't heard of it.

Thanks for the tips.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top