Solved

Delete Listbox Item Using Del key

Posted on 1997-10-28
2
425 Views
Last Modified: 2013-12-03
I would like to be able to delete an item listed in a dialog listbox by using the del key.  How do I go about it because in a dialog, keyboard input is only possible to an edit control.
0
Comment
Question by:Chris_m
2 Comments
 
LVL 1

Accepted Solution

by:
yl earned 100 total points
ID: 1408018
You should do the following:
1. Add the LBS_WANTKEYBOARDINPUT style to your listbox in the resource file where the dialog box is defined.
2. Add the following code in your dialog box function:
  // Assuming that the listbox is has Id of IDC_LISTBOX1.
  case WM_VKEYTOITEM:
    if (LOWORD(wParam) == VK_DELETE) {
       int iIndex = SendDlgItemMessage(hDlg, IDC_LISTBOX1, LB_GETCURSEL, 0, 0);
       if (iIndex >= 0)
          SendDlgItemMessage(hDlg, IDC_LISTBOX1, LB_DELETESTRING, iIndex, 0);
      }
      return (-1);

3. In case you're using win16 (and not win32) then replace the LOWORD(wParam) with wParam.

4. The delete key will be detected when the listbox has the keyboard focus.

0
 

Author Comment

by:Chris_m
ID: 1408019
Thanks for your help.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question