GetItemCount Retrieves the number of items in a list view control. GetItemData Retrieves the application-specific value associated with an item. GetItemPosition
如何获得当前选择项Current Item? GetSelectedCount() Retrieves the number of selected items in the list view control. 如何获得当前列表的列的数目? GetItemCount() Retrieves the number of items in a list view control. 如何取出每项的内容? GetItemText() Retrieves the text of a list view item or subitem.
GetItemCount() 不是获得行的总数吗?我是这样做的 int Item; CCenterMngDlg theDlg; Item=m_ctrllist.GetHotItem(); m_ctrllist.SetHotItem(0); int count=theDlg.pFields->Count; CString strtemp; for(int i=0;i<count;i++) { strtemp+=m_ctrllist.GetItemText(Item,i); } AfxMessageBox(strtemp); 结果是Item得到-1值,为什么这样呢?
jennyvenus(JennyVenus)恭喜你升为两星
结果是-1就证明当前没有处于鼠标前的ITEM,更多是你没有设置hot tracking 有效吧
POSITION pos = this->GetFirstSelectedItemPosition(); if (pos == NULL) TRACE0("No items were selected!\n"); else { while (pos) { int nItem = this->GetNextSelectedItem(pos); }
int nCount = GetItemCount();
CString cs; GetItemText(0,0,cs);
谢谢各位的解答,我是这样解决的。可是有一个问题没解决,for(int i=0;i<25;i++)中,25是一个常数,我想用count动态指定,不知道怎么做。按hhuangchunlin(林之韵) 朋友的说法应该用GetItemCount(),我马上去试,要能解决那真太感谢你们了。void tabdlg1::OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult) { // TODO: Add your control notification handler code here] POSITION pos = m_ctrllist.GetFirstSelectedItemPosition(); if(!pos) { AfxMessageBox("hi,将弹出新建用户对话框"); } else { AfxMessageBox("将弹出修改用户对话框"); int item=m_ctrllist.GetNextItem(-1,LVNI_SELECTED); CString strtemp[25]; int j=0; for(int i=0;i<25;i++) { strtemp[i]=m_ctrllist.GetItemText(item,i); if(strtemp[i]!="") { value[j]=strtemp[i]; j++; } } } *pResult = 0; }
GetSelectedCount() Retrieves the number of selected items in the list view control.
如何获得当前列表的列的数目?
GetItemCount() Retrieves the number of items in a list view control.
如何取出每项的内容?
GetItemText() Retrieves the text of a list view item or subitem.
CCenterMngDlg theDlg;
Item=m_ctrllist.GetHotItem();
m_ctrllist.SetHotItem(0);
int count=theDlg.pFields->Count;
CString strtemp;
for(int i=0;i<count;i++)
{
strtemp+=m_ctrllist.GetItemText(Item,i);
}
AfxMessageBox(strtemp);
结果是Item得到-1值,为什么这样呢?
if (pos == NULL)
TRACE0("No items were selected!\n");
else
{
while (pos)
{
int nItem = this->GetNextSelectedItem(pos);
}
GetItemText(0,0,cs);
{
// TODO: Add your control notification handler code here]
POSITION pos = m_ctrllist.GetFirstSelectedItemPosition();
if(!pos)
{
AfxMessageBox("hi,将弹出新建用户对话框");
}
else
{
AfxMessageBox("将弹出修改用户对话框");
int item=m_ctrllist.GetNextItem(-1,LVNI_SELECTED);
CString strtemp[25];
int j=0;
for(int i=0;i<25;i++)
{
strtemp[i]=m_ctrllist.GetItemText(item,i);
if(strtemp[i]!="")
{
value[j]=strtemp[i];
j++;
}
}
}
*pResult = 0;
}
所以前面有些人的解答是错误的。
今天又新遇到的问题
POSITION pos = m_ctrllist.GetFirstSelectedItemPosition();
if(!pos)
{}
else
{}
也是用你的代码。
根据你在MESSAGE里的方法,我已经解决了COUNT问题。再次表示感谢!