473,569 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trouble Selecting a ListViewItem Programmaticall y

I know it, I know it. It's come up a lot. I've done the Googling, but
the standard answer doesn't do what I expect it to. For the record, the
standard answer is: "Set the Selected property of a ListViewItem to
true." I also know from MSDN that the selection won't really take
effect until the ListView has focus.

My specific problem is that setting item.Select = true doesn't actually
select my item (or at least, doesn't highlight it). I'm implementing a
search feature, and the highlighting is kind of important.

Even more curious, Microsoft's own C# code sample at
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20 .en/CPref17/html/P_System_Window s_Forms_ListVie wItem_Selected. htm
(might need to get there through VS2005 documentation) illustrates my
problem exactly. The first list item does not get selected on list
population, even though the code tells it to do so. Selection seems to
work after a click on the button, but not before.

1) What's so magical about that button click?
2) Is this a bug in the framework?

Spanks

ff

Nov 17 '05 #1
2 3693
See comment inline.

"Fritz" <fr**********@h otmail.com> wrote in message
news:11******** *************@f 14g2000cwb.goog legroups.com...
I know it, I know it. It's come up a lot. I've done the Googling, but
the standard answer doesn't do what I expect it to. For the record, the
standard answer is: "Set the Selected property of a ListViewItem to
true." I also know from MSDN that the selection won't really take
effect until the ListView has focus.

My specific problem is that setting item.Select = true doesn't actually
select my item (or at least, doesn't highlight it). I'm implementing a
Yes, it is indeed SELECTED! However, wether the selected item is
highlighted or not is another question. ListView has a property called
"HideSelection" , which is default to TRUE, meaning, if the listview does not
have focus, the selected item(s) do not get highlighted.

So, your options are:
1. Set HideSelection to False. In this case, if the listview does not have
focus, the selected item(s) are highlighted in gray color (not usual blue);
2. Make sure the listview get focus when you need to show selection of the
listview.

search feature, and the highlighting is kind of important.

Even more curious, Microsoft's own C# code sample at
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20 .en/CPref17/html/P_System_Window s_Forms_ListVie wItem_Selected. htm
(might need to get there through VS2005 documentation) illustrates my
problem exactly. The first list item does not get selected on list
population, even though the code tells it to do so. Selection seems to
work after a click on the button, but not before.

1) What's so magical about that button click?
2) Is this a bug in the framework?

Spanks

ff

Nov 17 '05 #2

Norman Yuan wrote:
Yes, it is indeed SELECTED! However, wether the selected item is
highlighted or not is another question. ListView has a property called
"HideSelection" , which is default to TRUE, meaning, if the listview does not
have focus, the selected item(s) do not get highlighted.


Woohoo!! Thank you very much! The HideSelection property was the
answer.

That's been chafing me for days. If we're ever at happy hour together,
your next round's on me.

ff

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2403
by: james.dixon | last post by:
Hi I was wondering if anyone else had had this problem before (can't find anything on the web about it). I have three select elements (list boxes - from here on I'll refer to them as 'the list boxes'). Users can add and remove items from the list boxes. When the users are adding and removing items, the list boxes are single
3
2394
by: Marc W. | last post by:
Is there any way to do this? It would seem like it would be pretty obvious, but I can't find a method that does this. Thanks, Marc
4
9701
by: Paddy | last post by:
How do I select a subitem from a listview after clicking on the first column? Couldn't find it in MSDN. Thank you. Paddy.
10
11320
by: Danny Tuppeny | last post by:
Hi All, I'm trying to find the best way to select an item in a ListView using the Virtual mode. My "items" are business classes, and I have a reference to once I want to select (passed from another dialog). One way is to spin through the items and compare the .Tag property to my business object (code below), however I fear the casts are...
6
13083
by: grs | last post by:
The following is a code example from the Microsoft MSDN. My question is on the following three lines of code: ListViewItem item1 = new ListViewItem("item1",0); ListViewItem item2 = new ListViewItem("item2",1); ListViewItem item3 = new ListViewItem("item3",0); You would in most cases know the ListViewItem name or the number of items to...
2
1437
by: naikrovek | last post by:
Hello all. I have a ListView on a form, that has columns added at design-time but will be populated run-time. So, I know what the columns will be, and I know that I will have an arbitrary number of 'rows' in the ListView, anywhere from 1 to 100 or even 1000. The purpose of the program is to allow a user to keep an eye on tickets in a...
0
1071
by: Kluch | last post by:
I am trying to select and focus single ListViewItem and can't seem to do so, here is my code: IEnumerator * itemList = mLsvMyList->Items->GetEnumerator(); while (itemList->MoveNext()) { ListViewItem * currentItem = static_cast<ListViewItem*>(itemList->Current); String * tagData = static_cast<String*>(currentItem->Tag);...
3
15708
by: larry mckay | last post by:
anyone have the code to select and listview item or row (subitems) after a doubleclick event from a listview. *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
3
1276
by: Lars Netzel | last post by:
It seems like the ListView.SelectedItems is a ReadOnly Property.. How do I after a "populate" of a ListView preselect one or more Items? /Lars
0
7698
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8122
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7970
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1213
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.