CheckedItems collection - value from list

3 posts, 1 answers
  1. Spaso
    Spaso avatar
    5 posts
    Member since:
    Nov 2010

    Posted 01 Dec 2012 Link to this post

    I want to iterate by list of checked items and to get bind value from list. If I iterate through list by:
    foreach (object item in this.listBox.CheckedItems)
    {
        //How to
    }

    How to get values from the list if I have two fields bound in the list.
     For instance I would like to get value from the list by item.value1 and item.value2 but how.
    I'm not use MVVM.
    Thanks

  2. Answer
    Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 03 Dec 2012 Link to this post

    Hi Spaso,

    In the foreach loop you will have to cast the item to your custom object as shown bellow:

    foreach (var item in this.listBox1.CheckedItems)
    {
        MyDataItem myItem = item as MyDataItem;
        if(myItem != null)
        {
            var value1 = myItem.Value1;
            var value2 = myItem.Value2;
        }
    }

    The code above will work only if your custom object (ex: MyDataItem) contains the Value1 and Value2 properties. 

    If this does not answer your question, could you please elaborate a bit more on the scenario you have and what you're trying to achieve. I'd be glad to assist you further.

    Regards,
    Kiril Stanoev
    the Telerik team
    Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
  3. DevCraft banner
  4. Spaso
    Spaso avatar
    5 posts
    Member since:
    Nov 2010

    Posted 03 Dec 2012 Link to this post

    Thanks Kiril for your prompt answer.

    Well, I didn't use custom object so that was cause of my problem.
    Now I did it with my object and problem SOLVED.

    If I may give you some suggestions. It would be good to include some part of your answer into explanation of RadControls for WindowsPhone: CheckedItems Collection (online version and chm vesrion also). I think it would be helpfull to the others.
    Also, please update offline version of your help for controls (chm). For instance, there is no ImageButton control in it.
    Best regards

    Spaso Lazarevic
    MVP C#
Back to Top