POSITION GetFirstSelectedItemPosition( ) const; int GetNextSelectedItem( POSITION& pos ) constCString GetItemText( int nItem, int nSubItem ) const;
POSITION pos = pList->GetFirstSelectedItemPosition(); if (pos == NULL) TRACE0("No items were selected!\n"); else { while (pos) { int nItem = pList->GetNextSelectedItem(pos); // You could do your own processing on nItem here. } }
const; int GetNextSelectedItem(
POSITION& pos
) constCString GetItemText(
int nItem,
int nSubItem )
const;
if (pos == NULL)
TRACE0("No items were selected!\n");
else
{
while (pos)
{
int nItem = pList->GetNextSelectedItem(pos);
// You could do your own processing on nItem here.
}
}
比方说我现在鼠标选定了第三行,第三行的第一列的内容是"中国",我就是要获得这个字段啊,怎么写呢?用DataGrid很容易取得的,但是用ListCtrl我不会啊,MSDN上好象我找不到
CString CSpecialDlg::GetSelectedItem()
{
CString str; int nRow = m_listSpecial.GetItemCount(); for( int i=0; i<nRow; i++ )
{
if( m_listSpecialDay.GetItemState(i, LVIS_SELECTED)==LVIS_SELECTED )
{
str = m_listSpecialDay.GetItemText(i,j);//j为“中国对应的列”
return str
}
} return str;
}
就可以用GetNextSelectedItem( )取得第一项的编号,
取得编号以后就可以用 GetItemText()取得那行的任意一列的内容。
如:
OnLvnItemchangedBookRooms(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
int iCurrentSel = pNMLV->iItem; //得到当前行
m_strRoomNO = m_lcRoomList.GetItemText(iCurrentSel,0);
*pResult = 0;
}