需要派生你的CListCtrl,重载爽机事件的函数,添加你的代码
GetFirstSelectedItemPosition()返回第一个被选中的行的行数
Update用来更新,特定的item
BOOL Update(
int nItem
);Parameters
nItem
Index of the item to be updated.
GetFirstSelectedItemPosition()返回第一个被选中的行的行数
Update用来更新,特定的item
BOOL Update(
int nItem
);Parameters
nItem
Index of the item to be updated.
2 HitTest
3 Update,UpdateWindow,Invalidate记不清哪个最好使了。
要得到选择得item,用下面的函数:
int GetSelectedListItem(CListCtrl &listctrl)
{
int nCount = listctrl.GetItemCount();
if(nCount <= 0)
return -1; // no item int nSelCount = listctrl.GetSelectedCount();
if(nSelCount == 0)
return -2; // no selection LV_ITEM lvi;
lvi.mask = LVIF_STATE | LVIF_PARAM;
lvi.iSubItem = 0;
lvi.stateMask = 0xFFFF; // get all state flags
for (int i = 0; i < nCount; ++ i)
{
lvi.iItem = i;
listctrl.GetItem(&lvi);
if((lvi.state & LVIS_SELECTED) != 0)
break;
} if (i == nCount)
return -2; // no selection
return i;
}要更新内容:
SetItemText()。
ON_NOTIFY(NM_DBLCLK, IDC_CONTENT_LIST, OnDblclkContentList)
void CNewPathDlg::OnDblclkContentList(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
NM_LISTVIEW* pNMListView=(NM_LISTVIEW*)pNMHDR; int nSelected=pNMListView->iItem;
if(nSelected>=0)
{
//nSelected就是你双击的ITEM的index了。
}
*pResult = 0;
}
要写在哪儿????
int CPopList::CellRectFromPoint(CPoint & point, RECT * cellrect, int * col) const
{
int colnum; // Make sure that the ListView is in LVS_REPORT
if( (GetStyle() & LVS_TYPEMASK) != LVS_REPORT )
return -1; // Get the top and bottom row visible
int row = GetTopIndex();
int bottom = row + GetCountPerPage();
if( bottom > GetItemCount() )
bottom = GetItemCount();
// Get the number of columns
CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0);
int nColumnCount = pHeader->GetItemCount(); // Loop through the visible rows
for( ;row <=bottom;row++)
{
// Get bounding rect of item and check whether point falls in it.
CRect rect;
GetItemRect( row, &rect, LVIR_BOUNDS );
if( rect.PtInRect(point) )
{
// Now find the column
for( colnum = 0; colnum < nColumnCount; colnum++ )
{
int colwidth = GetColumnWidth(colnum);
if( point.x >= rect.left &&
point.x <= (rect.left + colwidth ) )
{
// Found the column
RECT rectClient;
GetClientRect( &rectClient );
if( point.x > rectClient.right )
return -1;
if( col )
*col = colnum;
rect.right = rect.left + colwidth;
if( rect.right > rectClient.right )
rect.right = rectClient.right;
*cellrect = rect;
return row;
}
rect.left += colwidth;
}
}
}
return -1;
}