Newbie questions

  • Thread starter Thread starter On The Corner
  • Start date Start date
O

On The Corner

Hi,
I'm a total VC++.NET newbie and I'm stuck with a couple of
stupid problems.
- I have a filled ListView. I'd like to select(or focus)
an Item from code, but I can't find a way to do it. I
can't find an Index property (or something like that)
which allows to be set.

- In a TextBox, when the event KeyDown is triggered, is
there a way to set the returned KeyCode. For example, when
the key 'K' is pressed, I'd like to put the 'H' char in
the TextBox.

I know these questions are quite stupid, but I've spent
all morning browsing the MSDN without finding anything !!!
Thanks in advance for your help !
 
To select an item :- SetItemState(nItem, LVIS_SELECTED, LVIS_SELECTED);

Index property :- See GetFirstSelectedItemPosition/GetNextSelectedItem in
MSDN

Handling character entry in TextBox :- Override PreTranslateMessage and
handle WM_CHAR in your CEdit derived class
 
Thank you for your help but I'm not using MFC but the .NET
framework.


-----Original Message-----
To select an item :- SetItemState(nItem, LVIS_SELECTED, LVIS_SELECTED);

Index property :- See
GetFirstSelectedItemPosition/GetNextSelectedItem in
 
Take a look at the KeyPress event of the edit control. In the help it is
listed as "Control.KeyPress Event".
 
On The Corner said:
Hi,
I'm a total VC++.NET newbie and I'm stuck with a couple of
stupid problems.
- I have a filled ListView. I'd like to select(or focus)
an Item from code, but I can't find a way to do it. I
can't find an Index property (or something like that)
which allows to be set.

- In a TextBox, when the event KeyDown is triggered, is
there a way to set the returned KeyCode. For example, when
the key 'K' is pressed, I'd like to put the 'H' char in
the TextBox.

I have not done this in a while, but you want to subclass the control. Use
the SetWindowLong() to substitute your own WndProc for the control.
Something like below :

WNDPROC oldEditProc; // to hold old edit control WndProc

LRESULT CALLBACK NewWndProc(HWND, UINT, WPARAM, LPARAM) //New WndProc for
control
{
... //handle WM_CHAR and replace wparam(?) with the character you want.
...
return CallWindowProc(oldEditProc, hwnd, msg, wParam, lParam);
}

oldWndProc = (WNDPROC) SetWindowLong(hwndEditControl, GWL_WNDPROC, (LONG)
NewWndProc); //replace WndProc for control in WM_CREATE of parent window

HTH,
M
 
Back
Top