Solved

Delete Listbox Item Using Del key

Posted on 1997-10-28
2
417 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
Comment Utility
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
Comment Utility
Thanks for your help.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
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…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 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

9 Experts available now in Live!

Get 1:1 Help Now