AcceptsReturn For a listView

  • Thread starter Thread starter mat
  • Start date Start date
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
 
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
 
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
 
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
 
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
 
Back
Top