Solved

Delete Listbox Item Using Del key

Posted on 1997-10-28
2
441 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

628 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