Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
CheckedListBox - Get Index Of Item By Key
Message
From
16/12/2009 17:19:01
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01439400
Message ID:
01439471
Views:
35
I'm assuming that you want to spin through the Items that have been checked by the user? Maybe not, but I'm not quite clear on what you're wanting to accomplish.

The CheckedListBox.Items is simply a collection of objects.
The CheckedListBox.CheckedItems is also a collection of objects.

So you'd use object in your foreach. And you can use Items.IndexOf() method to find the index.
foreach (object item in this.MyCheckedListBox.CheckedItems)
{
        // I'll let you fill in the blanks (this should give you a nudge)
	int x = this.MyCheckedListBox.Items.IndexOf(item);
}
~~Bonnie




>I'm trying to return the index of an item in a CheckedListBox using the value. The list was bound using:
>
>
>private void _LoadLists()
>{
>    string ObjectsQuery = "SELECT DataObjectId, AccessTableId, ObjectName FROM DataObject ORDER BY ObjectName";
>    DataSet dsObjects = _ExecuteQuery(ObjectsQuery);
>
>    chlObjects.DataSource = dsObjects.Tables[0];
>    chlObjects.DisplayMember = "ObjectName";
>    chlObjects.ValueMember = "DataObjectId"; 
>}
>
>
>Then, I have this method to get the index, but I'm not sure how to complete it:
>
>
>private int _GetIndexOfItemByKey(int Key)
>{
>    int RetVal = -1;
>
>    foreach (what??? Row in chlObjects.Items)
>    {
>     
>    }
>    
>    return RetVal;
>    
>}
>
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform