ClistCtrl高亮显示某一项

今天遇到一个小小的问题,就是高亮显示ListCtrl某一项,通过查阅MSDN,找到了相应函数,即:SetItemState,下面是MSDN中对该函数的相关说明.

--------------------------------------------------------------------------------------------------------------------

BOOL SetItemState(
   int
 nItem,
   LVITEM*
 pItem 
);
BOOL SetItemState(
   int
 nItem,
   UINT
 nState,
   UINT
 nMask 
);

Parameters
nItem
Index of the item whose state is to be set.
pItem
Address of an LVITEM structure, as described in the  Platform SDK. The structure's  stateMask member specifies which state bits to change, and the structure's  state member contains the new values for those bits. The other members are ignored.
nState
New values for the state bits.
nMask
Mask specifying which state bits to change.
Return Value

Nonzero if successful; otherwise zero.

Remarks

An item's "state" is a value that specifies the item's availability, indicates user actions, or otherwise reflects the item's status. A list view control changes some state bits, such as when the user selects an item. An application might change other state bits to disable or hide the item, or to specify an overlay image or state image.

--------------------------------------------------------------------------------------------------------------------

函数参数很简单,在这里就不作介绍了,一般情况下用下面的代码会正常高亮显示你所想要高亮显示的项:

  m_listCtrl.SetItemState(0,   LVIS_SELECTED,   LVIS_SELECTED   |   LVIS_FOCUSED);  

但是有的时候你会发现这段代码并不好用!上网搜....网上也大都是这么说的,没错呀,再加上一行代码试试...

listCtrl.SetItemState(index,   LVIS_SELECTED,   LVIS_SELECTED   |   LVIS_FOCUSED);   
  listCtrl.EnsureVisible(index,   FALSE);  

还是不行!这是为什么呢?!其实原因很简单:ListCtrl没有获得焦点!!!简单吧,哈哈..."千里之堤溃于蚁穴"(用这句话形容好像不太合适,大概是这个意思吧,文笔不好,大家多多见谅(*^__^*) 嘻嘻……),问题虽小,但可以说明一些问题,有的时候这个小小的问题也可能耗费你很长时间(个人深有体会!),如果你也遇到了类似问题,看到了这篇文章后问题解决了,我会感到很高兴,我今晚熬夜也"熬而无憾了"!

  下面是我遇到该问题的情形:

  (详见图片)

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值