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

Silverlight - Obtaining ListBox items

5 Answers 151 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Rob Lange
Top achievements
Rank 1
Rob Lange asked on 13 Apr 2010, 08:21 PM
I'm finding it's much easier said than done... I'm having no trouble grabbing the ListBox, but the Items (ItemCollection) is not giving me the information I'm looking for. When I iterate through the strings, they display the class name of the item in the listbox. I'm looking for the actual string being displayed in the listbox. How can I get that actual string?

5 Answers, 1 is accepted

Sort by
0
Rob Lange
Top achievements
Rank 1
answered on 13 Apr 2010, 10:26 PM
Time to solve my own problem...

If you run into this problem, you're probably using the 'ItemsSource' ability of your ListBox (ComboBox, etc) with a class you've created.

When WebAii's ItemCollection grabs the System.Windows.Controls.ItemCollection, instead of calling the DisplayMemberPath function, it calls the object.ToString() function on each element. The simple solution is to override the ToString() function. Problem Solved.

Now any UI changes to my Silverlight application fire events back to the main thread of my tests. Validation driven testing on Silverlight. Life is good. Thanks WebAii :)
0
Missing User
answered on 13 Apr 2010, 10:40 PM
Hi Rob,

Thanks for the update, I'm glad you got this working. I wasn't sure at first why you were not able to see the Item strings since I checked this on demo pages for ListBox, ComboBox and RadComboBox and was able to see them.

I was going to suggest:

TextBlock s = b.Items[b.SelectedIndex].Find.ByType<TextBlock>();
// or
IList<TextBlock> l = b.Find.AllByType<TextBlock>();

where b is the ListBox/ComboBox/RadComboBox.

Kind regards,
Nelson Sin
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Jie Liang
Top achievements
Rank 1
answered on 11 Jul 2010, 07:02 AM
Hi,

Are you sure
TextBlock s = b.Items[b.SelectedIndex].Find.ByType<TextBlock>();
will work?

b.Items[b.SelectedIndex] returns a string, which does not have the Find property.  I am using b as a ListBox.

BTW, what is ListBoxItem?  It seems that it has nothing to do with ListBox.Items.  Maybe I am wrong.

My question is, how to simulate a click on the item in the ListBox?

Thanks,

Jie


0
Missing User
answered on 12 Jul 2010, 10:06 PM
Hi Jie Liang,

Thanks for pointing this out, it looks like what I posted will not work for ListBox.

As a work around, you can try:

ListBox b = app.Find.ByType<ListBox>();
IList<ListBoxItem> l = b.Find.AllByType<ListBoxItem>();
l[0].Find.ByType<TextBlock>().User.Click();
// or
b.Find.ByText("Item Text").User.Click();

Items does seem a little strange in what it returns with respect to ListBox, so I'll try to find out what the collection is for.

Regards,
Nelson
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Arv
Top achievements
Rank 1
answered on 14 Feb 2011, 04:31 PM
Got my problem sorted in the end - could not remove my post.

Tags
General Discussions
Asked by
Rob Lange
Top achievements
Rank 1
Answers by
Rob Lange
Top achievements
Rank 1
Missing User
Jie Liang
Top achievements
Rank 1
Arv
Top achievements
Rank 1
Share this question
or