Click here to Skip to main content
15,897,187 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRemoving Items From A Listbox Pin
[d3m0n]23-May-05 2:26
[d3m0n]23-May-05 2:26 
GeneralRe: Removing Items From A Listbox Pin
Tom Archer23-May-05 2:31
Tom Archer23-May-05 2:31 
GeneralRe: Removing Items From A Listbox Pin
[d3m0n]23-May-05 2:54
[d3m0n]23-May-05 2:54 
GeneralRe: Removing Items From A Listbox Pin
Tom Archer23-May-05 2:58
Tom Archer23-May-05 2:58 
GeneralRe: Removing Items From A Listbox Pin
ThatsAlok23-May-05 3:03
ThatsAlok23-May-05 3:03 
GeneralRe: Removing Items From A Listbox Pin
[d3m0n]23-May-05 3:08
[d3m0n]23-May-05 3:08 
GeneralRe: Removing Items From A Listbox Pin
lynchspawn23-May-05 4:11
lynchspawn23-May-05 4:11 
GeneralRe: Removing Items From A Listbox Pin
Jack Puppy23-May-05 4:06
Jack Puppy23-May-05 4:06 
I whipped up a quick project and experienced the same thing.

It did work for me however if I set the focus to the add button prior to disable:

<br />
void CTestDlg::UpdateControls()<br />
{<br />
   BOOL bEnable = FALSE;<br />
<br />
   int nSelectedItem = m_listBox.GetCurSel();<br />
   if (nSelectedItem != LB_ERR)<br />
      bEnable = TRUE;<br />
<br />
    if (!bEnable)<br />
        m_btnAdd.SetFocus();<br />
   <br />
 <br />
   m_btnModify.EnableWindow(bEnable);<br />
   m_btnRemove.EnableWindow(bEnable);<br />
}<br />


I also tried using UpdateDialogControls w/command handlers, which worked, (autoset focus to list box when last item was removed) but it requires more work:

to the .h add
<br />
afx_msg LRESULT OnKickIdle(WPARAM wParam, LPARAM lParam);<br />


to the .cpp add
<br />
ON_MESSAGE(WM_KICKIDLE, OnKickIdle)<br />
<br />
LRESULT CTestDlg::OnKickIdle(WPARAM wParam, LPARAM lParam)<br />
{<br />
	UNREFERENCED_PARAMETER(wParam);<br />
	UNREFERENCED_PARAMETER(lParam);<br />
	UpdateDialogControls(this, FALSE);<br />
	return (0);<br />
}<br />
<br />


* For each button that needs to be enabled/disabled:

in .h, add:

<br />
afx_msg void OnUpdatexxxButton(CCmdUI* pCmdUI);<br />


in .cpp add:

<br />
ON_UPDATE_COMMAND_UI(IDC_xxx_BUTTON, OnUpdatexxxButton)<br />
<br />
void CTestDlg::OnUpdatexxxButton(CCmdUI* pCmdUI)<br />
{<br />
	pCmdUI->Enable(m_listBox.GetCurSel() != LB_ERR);<br />
}<br />


* You could also group their IDs if you wanted using ON_UPDATE_COMMAND_UI_RANGE


Suspicious | :suss: Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
GeneralRe: Removing Items From A Listbox Pin
[d3m0n]23-May-05 4:23
[d3m0n]23-May-05 4:23 
GeneralRe: Removing Items From A Listbox Pin
David Crow23-May-05 4:43
David Crow23-May-05 4:43 
GeneralRe: Removing Items From A Listbox Pin
[d3m0n]23-May-05 4:46
[d3m0n]23-May-05 4:46 
GeneralRe: Removing Items From A Listbox Pin
David Crow23-May-05 5:03
David Crow23-May-05 5:03 
GeneralRe: Removing Items From A Listbox Pin
[d3m0n]23-May-05 5:07
[d3m0n]23-May-05 5:07 
GeneralRe: Removing Items From A Listbox Pin
David Crow23-May-05 5:27
David Crow23-May-05 5:27 
GeneralReceiving SMS on PocketPC Pin
anevemkz23-May-05 2:21
anevemkz23-May-05 2:21 
Generalsockets vs file-dropoff Pin
Tom Archer23-May-05 1:38
Tom Archer23-May-05 1:38 
GeneralRe: sockets vs file-dropoff Pin
ThatsAlok23-May-05 2:00
ThatsAlok23-May-05 2:00 
GeneralRe: sockets vs file-dropoff Pin
Tom Archer23-May-05 2:05
Tom Archer23-May-05 2:05 
GeneralRe: sockets vs file-dropoff Pin
ThatsAlok23-May-05 2:22
ThatsAlok23-May-05 2:22 
GeneralRe: sockets vs file-dropoff Pin
Tom Archer23-May-05 2:30
Tom Archer23-May-05 2:30 
GeneralRe: sockets vs file-dropoff Pin
ThatsAlok23-May-05 2:36
ThatsAlok23-May-05 2:36 
GeneralRe: sockets vs file-dropoff Pin
Ryan Binns23-May-05 4:06
Ryan Binns23-May-05 4:06 
GeneralRe: sockets vs file-dropoff Pin
Tom Archer23-May-05 13:38
Tom Archer23-May-05 13:38 
GeneralRe: sockets vs file-dropoff Pin
ThatsAlok23-May-05 17:33
ThatsAlok23-May-05 17:33 
GeneralRe: sockets vs file-dropoff Pin
Ryan Binns23-May-05 4:12
Ryan Binns23-May-05 4:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.