获取listview详细信息 [英] Getting listview details

查看:87
本文介绍了获取listview详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从listcontrol中获取所选的行/列文本?

当我在listcontrol上选择任何文本时,我必须在状态栏上显示数据但我不知道top获取所选文本listcontrol的详细信息。

你可以帮我吗



我尝试了什么:



i尝试使用getitemtext(0,0)(例如)但它没有显示任何内容

How to get the selected row/column text from the listcontrol ?
When i selected any text on listcontrol that data i have to show on status bar but i have no idea top get the selected text details from listcontrol.
could you please help me here

What I have tried:

i tried with getitemtext(0,0)(for example) but its not showing anything

推荐答案

这取决于选择类型(单行或多行)。



要获取所选行的数量,请使用 CListCtrl :: GetSelectedCount() [ ^ ]。如果计数不为零则调用

This depends on the type of selection (single or multiple rows).

To get the numbers of selected rows use CListCtrl::GetSelectedCount() [^]. If the count is not zero call
prevItemIndex = GetNextItem(prevItemIndex, LVNI_SELECTED);

计数次数(或直到返回-1)其中 prevItemIndex 最初为-1。



或者使用 GetFirstSelectedItemPosition() GetFirstSelectedItemPosition()



如果您的报告列表未设置为完整行选择,则必须使用 GetItem()检查所选行的每一列,并在那里检查选择状态:

count times (or until -1 is returned) where prevItemIndex is -1 initially.

Alternatively use GetFirstSelectedItemPosition() and GetFirstSelectedItemPosition().

If your report list is not set to full row selection, you have to check each column of the selected rows using GetItem() and checking there for the selection state:

LVITEM item;
item.iItem = prevItemIndex;
item.mask = LVIF_STATE;
item.stateMask = LVIS_SELECTED;
GetItem(&item);
if (item.state & LVIS_SELECTED)
{
    // column is selected
}

将返回的索引传递给 GetItemText()检索文本。





如果你想在选择时做出反应更改(例如更新状态栏),处理 LVN_ITEMCHANGED通知代码(Windows) [ ^ ]:

Pass the returned index(es) to GetItemText() to retrieve the text.


If you want to react when the selection is changed (e.g. to update the status bar), handle the LVN_ITEMCHANGED notification code (Windows)[^]:

// Example for CListView derived class
// Message map entry:
ON_NOTIFY_REFLECT(LVN_ITEMCHANGED, OnLvnItemChanged)

void CMyListView::OnLvnItemChanged(NMHDR *pNMHDR, LRESULT *pResult)
{
    LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
    // Selection state has changed when LVIF_STATE is set and
    //  LVIS_SELECTED state differs
    if ((pNMLV->uChanged & LVIF_STATE) && ((pNMLV->uOldState ^ pNMLV->uNewState) & LVIS_SELECTED))
    {
        // pNMLV->iItem is the item and pNMLV->iItem the column
        //  for which the selection has changed
    }
    *pResult = 0;
}


这篇关于获取listview详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆