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

Posted on 2011-10-06
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.

Question by:MKItani
    LVL 8

    Accepted Solution

    LVL 16

    Assisted Solution

    by:Easwaran Paramasivam

    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

    LVL 11

    Assisted Solution

    Since this inherits from the ListBox control you should use FindString(+2 overloads) or FindStringExact(+2 overloads).

    You can get more information here: .

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

    Assisted Solution

    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.

    Featured Post

    Hire Top Freelancers to Complete C# Projects

    Source the talented Expert Exchange community
    for top quality work on your C# projects.

    Hire the best. Collaborate easily. Get quality work.

    Join & Write a Comment

    Article by: Ivo
    C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now