I have two CListCtrl objects in my form. I want selected list in both of them be same. How 开发者_如何学GoI can do it. I want duplicate the message that sent to a ClistCtrl and send to other one. How I can do it? if this is a good way? thanks herzl
So, essentially what you're saying is that you want the lists to be synchronized.
You can easily achieve that by adding an event handler to catch the user's selection inside you list control, by adding: ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST1, OnItemChangedList1)
to your dialog/window's message-map.
Inside OnItemChangedList1()
, get the index of the currently selected item by calling GetFirstSelectedItemPosition()
, and set that as the current index in your second list by calling SetSelectionMark()
.
This way, whenever the user will click on the 2nd item, for example, in List_A, the 2nd item in List_B will be selected as well.
There ought to be a function that brings that row into view, if it's not in view already, but I can't find it.
I hope that raps it up, ListView's have changed a lot since I've used them, but feel free to ask more if anything is unclear.
精彩评论