473,466 Members | 1,354 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Is it possible to use switch case for the ListView items?

25 New Member
I have a listView which has 4 items and respectively 4 subItems. What I am thinking of is if I can use a switch case for each of the item. Like case 1 for item1. case2 for item2 and so on. Each item will be checking for something different so I want them to be static. Well so far I could think of :
Expand|Select|Wrap|Line Numbers
  1.  private void listView1_DoubleClick(object sender, EventArgs e)
  2.         {
  3.             if (listView1.SelectedItems.Count == 1)
  4.             {
  5.  
  6.                 if (listView1.SelectedItems.Contains(listView1.TopItem))
  7.                 {
  8.  
  9.                     //Do Something
  10.                 }
  11.             }
  12.         }
  13.  
But here I am selecting only the very first item. How can I do for the next 3 items?
Hence I am thinking in terms of something like switch case.
Or is there some better solution for this?
Many thanks in advance.


Edited:
I am doing something as below:

Expand|Select|Wrap|Line Numbers
  1.  private void listView1_DoubleClick(object sender, EventArgs e)
  2.         {
  3.             ListView.SelectedListViewItemCollection myItems = this.listView1.SelectedItems;
  4.             foreach (ListViewItem item in myItems)
  5.             {
  6.                 if (item.Index == 0)
  7.                 {
  8.                     //Do something
  9.                 }
  10.             }
  11.         }
  12.  
  13.  
But still if there is a better way please do let me know as I am still learning.
Thank You :-)
Apr 15 '13 #1
0 986

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Islam Elkhayat | last post by:
In my Application i search my Employee database and view result in List View with 3 column.. here is the code: ######################################### private void textBox1_TextChanged(object...
0
by: Samuel R. Neff | last post by:
I'm having a index problem with ListView SubItems. If I add multiple columns to the listview and then add items with associated subitems, the ListView displays fine. Then if I delete a column via...
9
by: Eric S. | last post by:
Why doesn't something like this work? I get "a constant value is expected" on all 3 case statements. private DataGrid CurrentDataGrid(DataGrid firstDg, DataGrid secondDg) { try { switch...
6
by: Nick | last post by:
Hi there, I'm trying to implement drag-drop for my listview control in large icon view mode. Unfortunately the order of the items gets completely messed up upon inserting the item back into the...
12
by: garyusenet | last post by:
I have had no replies to my previous post so perhaps I didn't write it good enough. Please excuse new thread but i wanted to break from the last thread hopefully this thread will be better. ...
3
by: RT | last post by:
Is there any way to make Listview items invisible or otherwise keep them from displaying? Seems like temporarily removing, then restoring later would be a severe runtime hit.
0
by: Peter | last post by:
Hi, I have a problem with Listview using checkboxes. If i check items by code BEFORE the form is shown the Listview.Items are confused during the ItemChecked Event !!! After showing the...
2
by: Peter | last post by:
Hi, I have a problem with Listview using checkboxes. If i check items by code BEFORE the form is shown the Listview.Items are confused during the ItemChecked Event !!! After showing the...
1
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, In my application I need to periodically remove all current items from a ListView and add a new set into it. The following abbreviated code contains the basic idea: private void...
13
by: Satya | last post by:
Hi everyone, This is the first time iam posting excuse me if iam making any mistake. My question is iam using a switch case statement in which i have around 100 case statements to compare. so...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
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...
0
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...

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.