CListCtrl derived class and disabling item selection

Hello everybody.
I have a CListCtrl derived class wich is also owner draw. Now I need to 
disable selecting items. So user should be able to see the list and be able 
to scroll it and everything. But selecting items should be disabled. I wrote 
a handle for OnLButtonDown which give me an opportunity to handle mouse 
button clicking and so user can't select the item by mouse. But it is still 
possible by arrows. I tried to handle VKeyToItem but it aseems never get 
called. So in my case how can I disable selecting items by arrows also. Or 
is there any better way to do that all together?
PS: I was looking for some properties for a CListCtrl but didn't find 
anything useful.
Thanks

German Koninin


0
nomail4459 (42)
2/15/2007 2:23:35 PM
vc.mfc 33608 articles. 0 followers. Follow

5 Replies
2016 Views

Similar Articles

[PageSpeed] 31

Here is how I would do it.  I would catch the LVN_ITEMCHANGED message for 
the list ctrl and check to see if the item is being selected. If it is and 
it is disabled then I would simply unselected it.

//every other item is disabled!
BOOL CMyListCtrl::IsItemDisabled(UINT ItemID)
{
   return ItemID % 2 != 0;
}

void CMyListCtrl::OnLvnItemchanged(NMHDR *pNMHDR, LRESULT *pResult)
{
   LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
    //if item is being selected and is diabled
   if (IsItemDisabled(pNMLV->iItem) && (pNMLV->uNewState & LVIS_SELECTED) == 
LVIS_SELECTED)
   {
        //unselect it!
      SetItemState(pNMLV->iItem,0,LVIS_SELECTED);
   }
   *pResult = 0;
}

AliR.

"German Koninin" <nomail@available.com> wrote in message 
news:eoMskzQUHHA.4872@TK2MSFTNGP03.phx.gbl...
> Hello everybody.
> I have a CListCtrl derived class wich is also owner draw. Now I need to 
> disable selecting items. So user should be able to see the list and be 
> able to scroll it and everything. But selecting items should be disabled. 
> I wrote a handle for OnLButtonDown which give me an opportunity to handle 
> mouse button clicking and so user can't select the item by mouse. But it 
> is still possible by arrows. I tried to handle VKeyToItem but it aseems 
> never get called. So in my case how can I disable selecting items by 
> arrows also. Or is there any better way to do that all together?
> PS: I was looking for some properties for a CListCtrl but didn't find 
> anything useful.
> Thanks
>
> German Koninin
>
> 


0
AliR3470 (3235)
2/15/2007 4:29:14 PM
Well, you might consider looking at the LVN_ITEMCHANGING or LVN_ITEMACTIVATE instead of
going for the raw mouse click.  As you point out, this is insufficient.

Presumably you have some visual indication (e.g., gray text, or some other clue) that an
item is invalid.  What you might do is when the LVN_ITEMACTIVATE is received, simply scan
forward to the next enabled item and select it.  I've done this in a listbox using
LBN_SELCHANGE notifications.
				joe
On Thu, 15 Feb 2007 15:23:35 +0100, "German Koninin" <nomail@available.com> wrote:

>Hello everybody.
>I have a CListCtrl derived class wich is also owner draw. Now I need to 
>disable selecting items. So user should be able to see the list and be able 
>to scroll it and everything. But selecting items should be disabled. I wrote 
>a handle for OnLButtonDown which give me an opportunity to handle mouse 
>button clicking and so user can't select the item by mouse. But it is still 
>possible by arrows. I tried to handle VKeyToItem but it aseems never get 
>called. So in my case how can I disable selecting items by arrows also. Or 
>is there any better way to do that all together?
>PS: I was looking for some properties for a CListCtrl but didn't find 
>anything useful.
>Thanks
>
>German Koninin
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15972)
2/15/2007 4:29:22 PM
Oh One more thing, when you are unselecting an item but you still want the 
focus rect around the item then you might want to do this instead
if (....)

{

    //disable the item but still draw the focus rect

   SetItemState(pNMLV->iItem,LVIS_FOCUSED,LVIS_SELECTED|LVIS_FOCUSED);

}



AliR.




"AliR (VC++ MVP)" <AliR@online.nospam> wrote in message 
news:uT%Ah.22303$zH1.16901@newssvr29.news.prodigy.net...
> Here is how I would do it.  I would catch the LVN_ITEMCHANGED message for 
> the list ctrl and check to see if the item is being selected. If it is and 
> it is disabled then I would simply unselected it.
>
> //every other item is disabled!
> BOOL CMyListCtrl::IsItemDisabled(UINT ItemID)
> {
>   return ItemID % 2 != 0;
> }
>
> void CMyListCtrl::OnLvnItemchanged(NMHDR *pNMHDR, LRESULT *pResult)
> {
>   LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
>    //if item is being selected and is diabled
>   if (IsItemDisabled(pNMLV->iItem) && (pNMLV->uNewState & LVIS_SELECTED) 
> == LVIS_SELECTED)
>   {
>        //unselect it!
>      SetItemState(pNMLV->iItem,0,LVIS_SELECTED);
>   }
>   *pResult = 0;
> }
>
> AliR.
>
> "German Koninin" <nomail@available.com> wrote in message 
> news:eoMskzQUHHA.4872@TK2MSFTNGP03.phx.gbl...
>> Hello everybody.
>> I have a CListCtrl derived class wich is also owner draw. Now I need to 
>> disable selecting items. So user should be able to see the list and be 
>> able to scroll it and everything. But selecting items should be disabled. 
>> I wrote a handle for OnLButtonDown which give me an opportunity to handle 
>> mouse button clicking and so user can't select the item by mouse. But it 
>> is still possible by arrows. I tried to handle VKeyToItem but it aseems 
>> never get called. So in my case how can I disable selecting items by 
>> arrows also. Or is there any better way to do that all together?
>> PS: I was looking for some properties for a CListCtrl but didn't find 
>> anything useful.
>> Thanks
>>
>> German Koninin
>>
>>
>
> 


0
AliR3470 (3235)
2/15/2007 4:35:16 PM
I used
   SetItemState(pNMLV->iItem, 0, LVIS_SELECTED|LVIS_FOCUSED);
to completely remove selection.

Thank you all



"AliR (VC++ MVP)" <AliR@online.nospam> wrote in message 
news:8Z%Ah.22307$zH1.304@newssvr29.news.prodigy.net...
> Oh One more thing, when you are unselecting an item but you still want the 
> focus rect around the item then you might want to do this instead
> if (....)
>
> {
>
>    //disable the item but still draw the focus rect
>
>   SetItemState(pNMLV->iItem,LVIS_FOCUSED,LVIS_SELECTED|LVIS_FOCUSED);
>
> }
>
>
>
> AliR.
>
>
>
>
> "AliR (VC++ MVP)" <AliR@online.nospam> wrote in message 
> news:uT%Ah.22303$zH1.16901@newssvr29.news.prodigy.net...
>> Here is how I would do it.  I would catch the LVN_ITEMCHANGED message for 
>> the list ctrl and check to see if the item is being selected. If it is 
>> and it is disabled then I would simply unselected it.
>>
>> //every other item is disabled!
>> BOOL CMyListCtrl::IsItemDisabled(UINT ItemID)
>> {
>>   return ItemID % 2 != 0;
>> }
>>
>> void CMyListCtrl::OnLvnItemchanged(NMHDR *pNMHDR, LRESULT *pResult)
>> {
>>   LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
>>    //if item is being selected and is diabled
>>   if (IsItemDisabled(pNMLV->iItem) && (pNMLV->uNewState & LVIS_SELECTED) 
>> == LVIS_SELECTED)
>>   {
>>        //unselect it!
>>      SetItemState(pNMLV->iItem,0,LVIS_SELECTED);
>>   }
>>   *pResult = 0;
>> }
>>
>> AliR.
>>
>> "German Koninin" <nomail@available.com> wrote in message 
>> news:eoMskzQUHHA.4872@TK2MSFTNGP03.phx.gbl...
>>> Hello everybody.
>>> I have a CListCtrl derived class wich is also owner draw. Now I need to 
>>> disable selecting items. So user should be able to see the list and be 
>>> able to scroll it and everything. But selecting items should be 
>>> disabled. I wrote a handle for OnLButtonDown which give me an 
>>> opportunity to handle mouse button clicking and so user can't select the 
>>> item by mouse. But it is still possible by arrows. I tried to handle 
>>> VKeyToItem but it aseems never get called. So in my case how can I 
>>> disable selecting items by arrows also. Or is there any better way to do 
>>> that all together?
>>> PS: I was looking for some properties for a CListCtrl but didn't find 
>>> anything useful.
>>> Thanks
>>>
>>> German Koninin
>>>
>>>
>>
>>
>
> 


0
nomail4459 (42)
2/16/2007 9:50:05 AM
Keep in mind that if you don't let it draw the focus rect around a disabled 
item, and if the user is using the keyboard to move around, he will loose 
track of where he is at.

AliR.

"German Koninin" <nomail@available.com> wrote in message 
news:eVnNa$aUHHA.1200@TK2MSFTNGP04.phx.gbl...
>I used
>   SetItemState(pNMLV->iItem, 0, LVIS_SELECTED|LVIS_FOCUSED);
> to completely remove selection.
>
> Thank you all
>
>
>
> "AliR (VC++ MVP)" <AliR@online.nospam> wrote in message 
> news:8Z%Ah.22307$zH1.304@newssvr29.news.prodigy.net...
>> Oh One more thing, when you are unselecting an item but you still want 
>> the focus rect around the item then you might want to do this instead
>> if (....)
>>
>> {
>>
>>    //disable the item but still draw the focus rect
>>
>>   SetItemState(pNMLV->iItem,LVIS_FOCUSED,LVIS_SELECTED|LVIS_FOCUSED);
>>
>> }
>>
>>
>>
>> AliR.
>>
>>
>>
>>
>> "AliR (VC++ MVP)" <AliR@online.nospam> wrote in message 
>> news:uT%Ah.22303$zH1.16901@newssvr29.news.prodigy.net...
>>> Here is how I would do it.  I would catch the LVN_ITEMCHANGED message 
>>> for the list ctrl and check to see if the item is being selected. If it 
>>> is and it is disabled then I would simply unselected it.
>>>
>>> //every other item is disabled!
>>> BOOL CMyListCtrl::IsItemDisabled(UINT ItemID)
>>> {
>>>   return ItemID % 2 != 0;
>>> }
>>>
>>> void CMyListCtrl::OnLvnItemchanged(NMHDR *pNMHDR, LRESULT *pResult)
>>> {
>>>   LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
>>>    //if item is being selected and is diabled
>>>   if (IsItemDisabled(pNMLV->iItem) && (pNMLV->uNewState & LVIS_SELECTED) 
>>> == LVIS_SELECTED)
>>>   {
>>>        //unselect it!
>>>      SetItemState(pNMLV->iItem,0,LVIS_SELECTED);
>>>   }
>>>   *pResult = 0;
>>> }
>>>
>>> AliR.
>>>
>>> "German Koninin" <nomail@available.com> wrote in message 
>>> news:eoMskzQUHHA.4872@TK2MSFTNGP03.phx.gbl...
>>>> Hello everybody.
>>>> I have a CListCtrl derived class wich is also owner draw. Now I need to 
>>>> disable selecting items. So user should be able to see the list and be 
>>>> able to scroll it and everything. But selecting items should be 
>>>> disabled. I wrote a handle for OnLButtonDown which give me an 
>>>> opportunity to handle mouse button clicking and so user can't select 
>>>> the item by mouse. But it is still possible by arrows. I tried to 
>>>> handle VKeyToItem but it aseems never get called. So in my case how can 
>>>> I disable selecting items by arrows also. Or is there any better way to 
>>>> do that all together?
>>>> PS: I was looking for some properties for a CListCtrl but didn't find 
>>>> anything useful.
>>>> Thanks
>>>>
>>>> German Koninin
>>>>
>>>>
>>>
>>>
>>
>>
>
> 


0
AliR3470 (3235)
2/16/2007 3:44:31 PM
Reply:

Similar Artilces:

Create a bound class
Hello, Is it possible to create a class that is bound to a field? Any links / help along these lines is appreciated. Thanks swas swas wrote: > Hello, > > Is it possible to create a class that is bound to a field? > > Any links / help along these lines is appreciated. > > > Thanks > > > swas But what is meant by 'bound to a field'? What is the class's ultimate purpose? If by 'bound class', you're hoping you can get the class in the property list and select a field for its "Control Source...

Selective Column deletion #2
Hi, I'm not real familiar with writing code in Excel, so my question is probably fairly simple. I'm working with Census data and before importing it into SAS I want to clean it up a bit in Excel. The problem is that the Census summary tables give me three columns of information (an upper, lower, and estimate), when I only need one (estimate). The matrices I work with a usually in the 52x2000 range, so it gets very tedious to delete them by hand. Can excel handle a 'delete if' or 'select if, then delete' type of command. something like: delete if (column(contains(uppe...

Money 2004 problem with duplicate budget item
I'm not sure when this happened, but it has occurred sometime since after I upgraded to Money 2004 (from Money 98). I have a Direct Debit "scheduled bill" setup for a loan payment against my home. For some reason, this loan payment shows up as double the loan payment when I run my "How am I doing on my Budget" report. However, when I edit the budget, it only shows up once. I had removed and readded the scheduled payment of the loan to try to correct another problem I was having. Any help you can give would be great. Thanks, Ken I have the exact same prob...

Intercept Control-N in CDHtmlDialog derived class
I'm intercepting all the alt keys in my CDHtmlDialog derived dialog application, but I can't seem to intercept the control-N "new browser" key combination. Unlike CHtmlView, CDHtmlDialog doesn't have an OnNewWindow2 event handler. I'm using C++ in Visual Studio .Net 2003. I should know how to do this, but I don't. Hints or pointers to a fax are very welcome. Thanks, Jim Howard ...

summarizing selected data on a grid
I have a grid that I use to define attributes. I want to summarize only the selected "types" (i'm just using "x" to select on my grid). For example, by taking: A B C Type1 x Type2 x x Type3 x Type4 x x Type5 x x I want to output: A Type1 Type2 Type5 With similar output's for B & C. I could do it with if statements, but it's a pretty big grid, so I have a lot of blank rows. Is there a better way? Thanks. Hi! Have a look at your post: I suspect it has not reproduced as yo intended. The table of x's doesn't seem to match the scri...

Selecting multiple public folders
Hi, I'm running Exch2003 and Outlook 2003. I need to add a user to a group of public folders. In both Outlook and Exchange System manager I can only select one folder at a time. Is there any way around this problem? regards, Pete Pete Halasovski <pjh43@cam.ac.uk> wrote: > Hi, > > I'm running Exch2003 and Outlook 2003. I need to add a user to a > group of public folders. In both Outlook and Exchange System manager > I can only select one folder at a time. Is there any way around this > problem? > regards, > > Pete Set up your permissions on the...

Can't Delete, Can't move items and can't send/receive
My outlook had to be terminated due to a hangup. When I restarted outlook, it had to rebuild the database. After this occured, when I try to erace an e-mail, I get in error message stating "messaging interface has returned an unknown error. If problem presists, restart Outlook." When I try to move an e-mail I get an error message stating "Can't Move Item". When my outlook does a send and receive I get the following error message "Unkown Error 0x8004060C". Can anyone help?!?!?! ...

CListCtrl Header height change??
CListCtrl Header height change?? Is it possible to change the height of a CListCtrl Header.? Thanks Markus ...

Selected/Unselected Filter on User Security Child Windows GP10
In GP 10 the child windows within the Security Task Setup and Security Role Setup windows might be a little more user friendly if they had a filter for those items that are selected or not selected. Just a suggestion. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the message pane. h...

where do yu keep certain items
what would you do with item that you want to keep in your item list and want to keep them active but dont want them to show up in the purchase order. I know that there is a don't put on purchase order button in the options menu. But can you access that in a special report and how do you do that. thank you ...

Problems with CListCtrl
I'm having trouble with a CListCtrl object. I'm trying to automatically set the selected items of the list from my code. I try the following statement: m_List.SetItem (pos, 0, LVIF_STATE, NULL, 0, LVIS_SELECTED, LVIS_SELECTED, 0); The SetItem function returns non-zero, which supposedly means it was successful. However, I don't see any selection showing up. I even called RedrawItem on this list item, but it didn't help either. Anyone know about this? -Eric >I'm having trouble with a CListCtrl object. I'm trying to automatically >set the selected ite...

CTreeCtrl and CListCtrl problem
I use create a single document struct using MFC(explore style).The left of the window is CLeftView class(which inherit CTreeView).The right is CBrowserView which inherit CListView.I want to display the content of a directory in the right(CListview) when user click the item of the ctreectrl. In the LeftViw I add method "void CLeftView::OnClickItem (NMHDR* pNMHDR, LRESULT* pResult)" because I want to know which item be clicked by user. ////////////////Leftview////////////////////// CTreeCtrl& mtree=GetTreeCtrl(); HTREEITEM item=mtree.GetSelectedItem(); data=mtree.GetItemDat...

Showing number series in query for grouped items
Hi, I have a stock table which has serial numbers for each item. I want a query which groups the item types and shows the first and last serial numbers for that item type along with how many. Eg. 10 x mobile phones first serial number = xxx1, last serial number = xx10. I tried the first, last, min and max functions but they continue to group and show each of the 10 items individually. Any ideas?? Thanks On Thu, 14 Feb 2008 04:27:01 -0800, Flanders <Flanders@discussions.microsoft.com> wrote: >Hi, > >I have a stock table which has serial numbers for each item. I want ...

Quest: CAsyncSocket derived sockets...
Is it possible to get see if a Server Socket obj has been already accepted or if it is not in use and is ready to be accepted? ...

runtime error class not registered
When I open Outlook 2003 I get an error message "A Runtime Error has occurred, do you wish to debug? Line 297 Error: Class not Registered." I upgraded from Office 2000. I have Norton @005 on my computer and never received this message before. ...

Exmerge Items from the Dumpster
I'm using Exmerge and choosing the option to extract 'Items from the dumpster.' However, when I open up the pst file that is created, I don't see any of the items from the dumpster. I have verified that I have Send As and Receive As rights over the database. I've also verified that there are actually items in the dumpster to extract. What else am I missing...? when you use exmerge to extract these items, they will appear in the folders they were in just prior to being sent to the dumpster... -- Susan Conkey [MVP] "Adoyt" <Adoyt@discussions.microso...

How do I disable automatic date formatting in excel?
I am importing data into Excel which contains codes. Some of the codes are similar to dates (ex. 4feb1) and they are automatically converted. I need the codes to remain as is. Import it as text Regards, Peo Sjoblom "tcuneio" wrote: > I am importing data into Excel which contains codes. Some of the codes are > similar to dates (ex. 4feb1) and they are automatically converted. I need > the codes to remain as is. I will see if I can control this. I'm importing data directly from AutoCAD and am not sure that I can control this. If I can't, is there no o...

Forwading Email of a Disabled User Account
Hello: I have disable a user account in ADUC. I have been asked to forward this persons email to another user. I have configured the email forwarding in ADUC as well. My question is this, do I have to re-enable the user account for e-mail to work, or can I leave the account disabled? Any help is appreciated. Thank you. It needs to be enabled in order to apply forwarding rules. "TechieGirl" <nospam@nospam.net> wrote in message news:%23FS45pVQGHA.5924@TK2MSFTNGP09.phx.gbl... > Hello: > > I have disable a user account in ADUC. I have been asked to forward ...

CListCtrl and sub item editting
Hi, Is it possible to implement CListCtrl sub item editting without creating a custom ctrl? I am using VS2003. TIA Tony >Is it possible to implement CListCtrl sub item editting without creating a >custom ctrl? Tony , There's no built-in support for this, so no, you have to provide some implementation for this. Have a look on sites such as CodeGuru and CodeProject, they'll have examples. Dave Thanks Dave, I've seen examples, I just wasnt sure if I needed my own ctrl. Regards Tony "David Lowndes" <DavidL@example.invalid> wrote in message news:k...

disable/enable CButton
Hi, To enable or disable a button, I call "MyButton.EnableWindow(flag);" but how do I check the state before before calling "EnableWindow()"? Thank you, Paul "Paul" <Paul@discussions.microsoft.com> wrote in message news:DFAE33F2-4352-4C7F-AB4A-ED5F720D937C@microsoft.com... > Hi, > > To enable or disable a button, I call "MyButton.EnableWindow(flag);" but how > do I check the state before before calling "EnableWindow()"? > Use BOOL CWnd::IsWindowEnabled() Tim "Tim" <thpetersen@hotmail.com> wrote in ...

all of my calendars items
I just transfered my outlook data files to a new hard drive with new install of office 2007. Have Blackberry desktop too. All of my calander items older than 2 weeks are now gone. The archive folder only has future items. any ideas? what is the 'keep for' setting on the blackberry? see http://www.slipstick.com/calendar/missing_appt.asp -- Diane Poremsky [MVP - Outlook] Outlook Tips: http://www.outlook-tips.net/ Outlook & Exchange Solutions Center: http://www.slipstick.com/ Outlook Tips by email: mailto:dailytips-subscribe-request@lists.outlooktips.net EMO - ...

Generate c# proxy class from IBM websphere (AXIS) webservice WSDL.
Hi, I am having problems with generating a c# proxy class from a IBM websphere WSDL file, when running the wsdl.exe to create the c# proxy file command i recieve an error: Warning: one or more operations were skipped. Warnings were encountered. Review generated source comments for more details. Writing file 'c:\proxyclass.cs'. After reviewing the created proxyclass.cs i find that the following error message: // CODEGEN: The operation binding 'CustomerUpdate' from namespace 'http://www.mywebsite.com/webservices/wsdl/Service.wsdl' was ignored. Missing soap:body input...

Empty Deleted Items on Exit isn't working
This has been the case since I moved to WLM. I use it for my Live mail account and no matter what, the Deleted Items folder remains populated after exit and later reopening WLM. Am I missing a setting somewhere? It will not work for a hotmail account set in WLM as a HTTP account "Michael" <Michael@discussions.microsoft.com> wrote in message news:1C01C084-C013-4E59-AC58-A7F8ECFE2CB6@microsoft.com... > This has been the case since I moved to WLM. I use it for my Live mail > account and no matter what, the Deleted Items folder remains populated > after ...

Duplicate Items #2
Duplicate Items are showing up in store operations. They have the same exact ILC and HQID some times it gets duplicated 100,000 of times. No other process than HQ worksheets are hitting this database. On version 2.0.0105 -- Bart M ...

Filegroup restore used to selectively refresh filegroup in 2nd db.
I have TestDB1 comprised of 5 filegroups, which I've completed full/log backups to to restore as TestDB2. When data changes within one filegroup on TestDB1, I've taken a diff' + tlog backup and tried to use it to restore on TestDB2 so that same filegroup would be essentially refreshed. My execution sequence uses the last full, last diff', and tlog from TestDB1 but this doesn't work? Why? Is there a way to do this in SQL 2K8? Thx. -CqlBoy Message applying full backup: >Processed 16 pages for database 'FGTestRestore', file 'FGTest_fg2' ...