This is a migrated thread and some comments may be shown as answers.

CheckedItems collection - value from list

2 Answers 89 Views
DataBoundListBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Spaso
Top achievements
Rank 1
Spaso asked on 01 Dec 2012, 12:30 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Kiril Stanoev
Telerik team
answered on 03 Dec 2012, 10:19 AM
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.
0
Spaso
Top achievements
Rank 1
answered on 03 Dec 2012, 08:26 PM
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#
Tags
DataBoundListBox
Asked by
Spaso
Top achievements
Rank 1
Answers by
Kiril Stanoev
Telerik team
Spaso
Top achievements
Rank 1
Share this question
or