void CLryEDBQryView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) { CListCtrl *ListCtrl = (CListCtrl *)&GetListCtrl(); CLryEDBQryDoc *pDoc = (CLryEDBQryDoc *)GetDocument(); CLryEDBQryDoc::CRowObj *rowInfo; int i; switch(lHint) { case 0: FillList(); //填写表格 break; case 1: try { i = pDoc->Rs->AbsolutePosition-1; ListCtrl->EnsureVisible(i,TRUE); } catch(_com_error &e) { dump_com_error(e); } break; case 2: rowInfo = (CLryEDBQryDoc::CRowObj*)pHint; ListCtrl->DeleteItem(rowInfo->RowNO); ListCtrl->Update(rowInfo->RowNO); break; default: break; } }
// -------------------------------------------------------- // AutoScroll // // Ensure selected item is in middle of list // -------------------------------------------------------- void CThirdPage::AutoScroll( CListCtrl & list, int nIndex ) { // //<rdar://problem/4528853> mDNS: When auto-highlighting items in lists, scroll list so highlighted item is in the middle // int top; int count; list.EnsureVisible( nIndex, FALSE ); top = list.GetTopIndex(); count = list.GetCountPerPage(); if ( ( nIndex == top ) || ( ( nIndex + 1 ) == ( top + count ) ) ) { CRect rect; int rows; rows = ( count / 2 ); if ( nIndex == top ) { list.GetItemRect(0, rect, LVIR_BOUNDS); list.Scroll( CPoint( 0, rows * rect.Height() * -1 ) ); } else { list.GetItemRect(0, rect, LVIR_BOUNDS); list.Scroll( CPoint( 0, rows * rect.Height() ) ); } } }
void CModulePropertiesDlg::SelectSong(int Song) { CListCtrl *pSongList = static_cast<CListCtrl*>(GetDlgItem(IDC_SONGLIST)); ASSERT(Song >= 0); pSongList->SetItemState(Song, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); pSongList->EnsureVisible(Song, FALSE); }
//===============Function=============== void CDialogStatus::InsertMessageList(IN string strMessage) { CTime CurrentTime = CTime::GetCurrentTime(); CListCtrl *pStatusList = (CListCtrl*)GetDlgItem(IDC_LIST_STATUS); if (NULL != pStatusList) { int nIndex = pStatusList->GetItemCount(); pStatusList->InsertItem(nIndex, CurrentTime.Format("%H:%M:%S")); pStatusList->SetItemText(nIndex, 2, strMessage.c_str()); pStatusList->EnsureVisible(nIndex, FALSE); } }
BOOL ArxDbgUtils::setCurSel(CListCtrl& listCtrl, int index) { if (index == -1) { for (int row = 0; row < listCtrl.GetItemCount(); row++) { // turn off any currently selected items if (listCtrl.GetItemState(row, LVIS_SELECTED) & LVIS_SELECTED) listCtrl.SetItemState(row, 0, LVIS_SELECTED | LVIS_FOCUSED); } return TRUE; } else { listCtrl.EnsureVisible(index, TRUE); return listCtrl.SetItemState(index, (LVIS_SELECTED | LVIS_FOCUSED), (LVIS_SELECTED | LVIS_FOCUSED)); } }
// @pymethod int|PyCListCtrl|EnsureVisible|Ensures that a list view item is visible in its list view control. PyObject *PyCListCtrl_EnsureVisible( PyObject *self, PyObject *args ) { CListCtrl *pList = GetListCtrl(self); if (!pList) return NULL; int item; BOOL bPartialOK; // @pyparm int|item||The index of item to edit. // @pyparm int|bPartialOK||Specifies whether partial visibility is acceptable. if (!PyArg_ParseTuple( args, "ii:EnsureVisible", &item, &bPartialOK)) return NULL; GUI_BGN_SAVE; BOOL ok = pList->EnsureVisible(item,bPartialOK); GUI_END_SAVE; if (!ok) RETURN_ERR("EnsureVisible failed"); RETURN_NONE; }
int ColumnSort(CListCtrl& list, int iSubItem, // column number (0..n-1) or -1=> last column UINT state) // CS_SORT : sort in the same order // CS_REVERSE : sort reverse // CS_FOR, CS_BACK : sort command // CS_SELVIS : 0=> show the selected item { // CS_SORTICON : icon display CHeaderCtrl *pHeader = list.GetHeaderCtrl(); int ix = pHeader->GetItemCount(); HDITEM hi; if (iSubItem >= ix) iSubItem = -1; // search the old sorted column hi.mask = HDI_IMAGE|HDI_FORMAT|HDI_LPARAM; while (--ix >= 0) { pHeader->GetItem(ix, &hi); if (hi.iImage == 0) continue; if (iSubItem >= 0 && ix != iSubItem) { // delete old display icon hi.iImage = 0; // hi.lParam |= STI_REVERSE; // ******************* hi.fmt &= ~HDF_IMAGE; pHeader->SetItem(ix, &hi); } break; } if (iSubItem < 0) { if (ix < 0) return -3; // a sorted column is not define iSubItem = ix; // there is the old column } // set the new display icon pHeader->GetItem(iSubItem, &hi); if (hi.lParam == 0) return -2; // sort disable for this column switch (state & 0x0003) { case CS_SORT : break; // in the same order case CS_REVERSE: hi.lParam ^= 1; break; // in the revers order case CS_ASCEND : hi.lParam &= ~1; break; // to impose ascending order case CS_DESCEND: hi.lParam |= 1; break; // to inpose descending order } hi.iImage = hi.lParam; if (state & CS_SORTICON) hi.fmt |= HDF_IMAGE; // the icon pHeader->SetItem(iSubItem, &hi); SortTextItems(list, iSubItem, short(hi.lParam)); if ((state & CS_SELVISIBLE) == 0) { // Make that the selected item continue to stay visible POSITION pos = list.GetFirstSelectedItemPosition(); if (pos) { // search the seleted item int no = list.GetNextSelectedItem(pos); list.EnsureVisible(no, FALSE); return no; // selected item } } return -1; }