Rank: Administration
Groups: AcademicCoachingSchool, admin, Administration, BookSeller, CatholicSchool, CoachingAdult, CoachingProfessional, CoachingSports, ExtraCurriculumCoaching, IndependentSchool, Moderator, MusicTeacher, PrivateSchool, PublicSchool, SelectiveSchool, tutor Joined: 23/11/2008(UTC) Posts: 523
|
How to make select all command fast?
Using keyboard shortcuts (selecting first row and then the last row by Shift+End to Select All in ClistCtrl is almost instantly done. However, using a loop to select 500+ rows in a list control CListCtrl by SetItemState on a Select All command (button click) programmatically can be slow, very unresponsive. Code: SetRedraw(false); int nItems = GetItemCount(); for(int i=0; i < nItems; ++i)
SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
SetRedraw(true);
Nevertheless, there is a undocumented -1 options which is much faster. It works almost instantly for me even if I have more than 1000 rows.
Code:SetItemState(-1, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
SetSelectionMark(-1);
The same trick applies to deselect all. Code:SetItemState(-1, 0, LVIS_SELECTED | LVIS_FOCUSED);
For the CTRL+A behaviour I just hooked the following into the pretranslate message:
Code: // hook to catch ctrl-a key for "select all"
// and ctrl-i key for "invert selection
if( pMsg->message == WM_CHAR )
{
TCHAR chr = static_cast<TCHAR>(pMsg->wParam);
switch( chr )
{
case 0x01: // 0x01 is the key code for ctrl-a and also for ctrl-A
{
SelectAll();
break;
}
/*case 0x09: // 0x09 is the key code for ctrl-i and ctrl-I
{
OnInvertSelection();
break;
}*/
}
}
Edited by user Wednesday, 25 October 2017 7:03:10 AM(UTC)
| Reason: Not specified
|