Hi,
I have a form with a listview and several textboxes. When the user selects a row, the values of the columns are written to the textboxes. Now I want the focus to be on the first textbox that the user can immediately edit the text. Unfortunately I'm not successful. While the left mousebutton is pressed, my code works. But when I release the mousebutton, the focus jumps back to the listview. I tried a lot of combinations where to put my code for focus change, but at the end allways the listview has the focus.
Can anybody tell me how to do that or is it impossible? ???
Thanks a lot.
Regards Rainer
You must be trying to set focus to your textboxes while you are still inside the mousebutton handler for the ListView. You should postmessage a user defined message to your form's custom message handler and respond to that message there by using setFocus. I have seen this "problem" so many times in the past and this is the easiest and most reliable solution because using PostMessage allows the mousebutton handler to fully finish before the SetFocus gets called.
Thank you Paul.
Of course I tried this before posting - but it doesn't work right. If I post my message in WM_LBUTTONDOWN section it works as long as the button is pressed. When I release the button, the focus jumps back to the listview. When I put it in WM_LBUTTONUP it works on a emty line of listview (nothing will be selected). But if I use a filled line no event ocurs until I make a double click! A single click produces no WM_LBUTTONUP event. Why? Is there a better place than WM_LBUTTONUP?
I succeed when I put ONE_CKLICK_ACTIVATE to TRUE and catch the WM_NOTIFY message %LVN_ITEMACTIVATE. But there I have a delay of one second, until the focus changes - not good!
Can you post your code (or send it to me) so I can investigate????????
Okay, I created a simple sample project and I see the problem you are experiencing. Give me some time to work on a solution.
Okay, a solution didn't take long at all :) Do not try to set focus during the LVN_ITEMCHANGED, but rather do it in the NM_CLICK notification message.
Function FORM1_CUSTOM ( _
hWndForm As Dword, _ ' handle of Form
wMsg As Long, _ ' type of message
wParam As Dword, _ ' first message parameter
lParam As Long _ ' second message parameter
) As Long
Local pNMLV As NM_LISTVIEW Ptr
Select Case wMsg
Case %WM_NOTIFY
pNMLV = lParam
Select Case @pNMLV.hdr.idfrom
Case IDC_FORM1_LISTVIEW1 ' notify message from the listview control
Select Case @pNMLV.hdr.code
Case %NM_CLICK 'left click
SetFocus HWND_FORM1_TEXT1
Case %NM_DBLCLK 'left double-click
Case %NM_RCLICK ' right click
Case %NM_RDBLCLK 'right double-click
End Select
End Select
End Select
End Function
You don't even seem to need to have to PostMessage. A simple call to SetFocus in the NM_CLICK seems to work just fine.
Hi Paul,
great!!! It works exactly as I want! ;D Thanks a lot. (Sorry, that I haven't answered before - it's because of the timelag, I'm from Germany!)
Rainer :D