Solved

Delete Listbox Item Using Del key

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

739 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