Solved

Delete Listbox Item Using Del key

Posted on 1997-10-28
2
419 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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…

895 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now