Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
CheckedListBox - Get Index Of Item By Key
Message
De
16/12/2009 17:19:01
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01439400
Message ID:
01439471
Vues:
34
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform