AcceptsReturn For a listView

M

mat

Hello!

Okay, I have a ListView (contained inside a USerControl) on a form
with an accept button. However, I want something to happen when the
User hits Enter/Return with focus on the ListView. Problem is this
doesn't work when an accept button is set for the form.

The TextBox has a AcceptsReturn property but Listviews do not. Does
anyone know
how I can acheive similer functionality.

Catching the KeyDown in a subclassed Listview does not work.
Neither does OnKeyDown...


any ideas would be gratefully recieved :)

thanks,

mat
 
C

Claes Bergefall

So don't set the AcceptButton property then!
Or turn it off when the ListView gets focus
(and back on when it looses focus)

/claes
 
M

mat

Not a very clever response that really, is it?!

Obviously I want the functionality of the AcceptButton!

I have figured it out now anyway:

I implemented an AcceptsReturn property in a subclassed ListView.
I then overrode the ProcessDialogKey:

protected override bool ProcessDialogKey(System.Windows.Forms.Keys keyData)
{
if(keyData == Keys.Enter && this.AcceptsReturn)
keyData = 0;

return base.ProcessDialogKey(keyData);
}

I can then pick up the Return Button from a listView using the old KeyDown event!

Fantastic eh?

mat
 
C

Claes Bergefall

Not a very clever response that really, is it?!

Actually, the second part should work (turn it of when the
listview gets focus and turn it back on when it looses it)

/claes
 
M

mat holton

Actually, the second part should work (turn it of when the
listview gets focus and turn it back on when it looses it)

Yeah, you are right, sorry about my flippent reply. Unfortunatly your
proposed method would have to be implemented for all uses of a listview,
whilst my method only need to be done once!

Thanks for the help anyway!

mat
 

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