Automatically exported from code.google.com/p/advcombobox
0
stars
0
forks
source link
If you set the control AutoSuggest and you input the first letter and then RETURN, the first time , it works well. ut if you input again and then RETURN, it will fail #8
1: http://www.codeproject.com/Messages/457856/Bug-report.aspx
It can be fixed in AdvComboBox.cpp Line 1348.
if( m_pDropWnd )
{
int nPos = m_pDropWnd->GetListBoxPtr()->GetCurSel();
if(nPos>=0)//Here the nPos should be checked.
SendMessage( WM_SELECTED_ITEM, (WPARAM)nPos );
}
2: http://www.codeproject.com/Messages/815022/Re-Bug-report.aspx
I had this problem too, and although leinwpu's suggestion prevents an
exception, it leaves the listbox hanging open for me after pressing enter if
GetCurSel failed. I made the following change in the referenced code in
CAdvComboBox::PreTranslateMessage:
int nPos = m_pDropWnd->GetListBoxPtr()->GetCurSel();
if (nPos != LB_ERR)
SendMessage( WM_SELECTED_ITEM, (WPARAM)nPos );
else
OnDestroyDropdownList(0,0);
If another change discussed below is made, I have only seen LB_ERR returned
when the dropwnd is open but the list is empty.
The real fix for me starts here. The problem that started the thread seems to
be caused in CAdvComboBox::CreateDropList by the line:
m_pDropWnd->GetListBoxPtr()->SetCurSel( m_nCurSel );
m_nCurSel appears to be an index into CAdvComboBox::m_list, the complete list,
although the actual list (droplist) could be the suggestlist, a subset, if
CreateDropList was called from OnUpdateEdit. This means that if the index of
the selected item in the full list was higher than the size of the suggestlist,
the SetCurSel call will fail, and subsequent GetCurSel calls will also fail
like that in PreTranslateMessage. Rather than try to correct the use of the
wrong index, I just added the following code:
if (m_nCurSel > ((int)droplist.size() - 1))
m_nCurSel = 0;
before the SetCurSel line in CAdvComboBox::CreateDropList. This won't entirely
solve all problems though if the m_nCurSel index isn't greater than the size of
the suggestlist, so I also changed some code in CAdvComboBox::OnUpdateEdit as
follows:
if( suggestlist.size() != 0 )
{
m_nCurSel = 0; // New
CreateDropList( suggestlist );
}
Incidentally, while I was tracking down the m_nCurSel index problem, I made a
small related change to CDropListBox::SetCurSel. This function is called from
CreateDropList, as noted above, when the droplist is being created. The
CDropListBox::SetCurSel function calls GetCurSel before CListBox::SetCurSel is
called, so GetCurSel returns LB_ERR because no item is selected at that point.
I don't know whether this would cause an error or not, because the return value
is used in processing disabled items in the listbox, which I haven't used.
Anyway, I made the following change in CDropListBox::SetCurSel:
int nCur = GetCurSel();
if (nCur < 0) // new
{
nCur = 0;
} // end new
I hope Mathias wasn't counting on nCur being -1 (LB_ERR) the first time
through! If so, I just broke it.
Original issue reported on code.google.com by mathias....@gmail.com on 29 Sep 2010 at 8:26
Original issue reported on code.google.com by
mathias....@gmail.com
on 29 Sep 2010 at 8:26