Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

how i can get the index of the checkedlistbox item according to the value+C#+VS 2008+Window application

Posted on 2011-10-06
4
Medium Priority
?
1,053 Views
Last Modified: 2012-05-12
i want to get the index of the checkedlistbox item according to the value, so i have used
string value="hello";
// but all the items the answer is -1, and i sure that there is a item of value equal hello in the list
int getIndex=CheckedListBox.Items.IndexOf(value);
i read a lot of the internet and many people face this problem.

regards,
0
Comment
Question by:MKItani
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
guvera earned 500 total points
ID: 36929123
0
 
LVL 16

Assisted Solution

by:Easwaran Paramasivam
Easwaran Paramasivam earned 500 total points
ID: 36929129
http://visualcsharptutorials.com/2011/03/checkedlistbox-control/

In the checkedList_ItemCheck event you can get the index by event arguments.

One more option there, loop through all the items in the checklistbox and if the value is your String then return the index.


if(myCheckedListBox.Count != 0) 
{  
  string s = "YourSring";    
  for(int i = 0; i <= myCheckedListBox.Count - 1 ; i++)  
  {      
   if (myCheckedListBox[i] == s
    retrun i;
  }
}

Open in new window

0
 
LVL 11

Assisted Solution

by:Kelvin McDaniel
Kelvin McDaniel earned 1000 total points
ID: 36930650
Since this inherits from the ListBox control you should use FindString(+2 overloads) or FindStringExact(+2 overloads).

You can get more information here: http://msdn.microsoft.com/en-us/library/system.windows.forms.checkedlistbox.aspx .

I just tested this and got the expected result... check the screenshot.
 Screenshot of CheckedListBox and positions of specific items in list.
0
 
LVL 11

Assisted Solution

by:Kelvin McDaniel
Kelvin McDaniel earned 1000 total points
ID: 36930663
Just saw that you'll need to be using the v3.5 framework to use the FindString() method... which I assume you are since you're IDE is VS2008.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question