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

How do you read/initialize the selected item?

8 Answers 137 Views
LoopingList
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Perry
Top achievements
Rank 1
Perry asked on 15 Dec 2011, 09:20 AM
Hello,

I'm trying to implement a simple integer loopinglist.  I'd like to initialize the starting values for a simple loopinglist, and or be able to read the item, before the user has started selection.  From the sparse documentation, I guess the method SelectedIndexChanged is used to read the item after it's been selected, but if I want to read and or initialize the value (during the constructor) I don't know what to use.  BTW, I can read the values after spinning the looping list.

-Regards,
Perry

8 Answers, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 15 Dec 2011, 03:07 PM
Hi Perry,

Thank you for your question.

Could you please elaborate a bit more on what is missing in our documentation so that we can update it accordingly.

To set the items for RadLoopingList, you need to create a LoopingListDataSource. Then you need to create event handlers for the two events that get fired during the initialization of the list: ItemNeeded and ItemUpdated. Inside the event handlers you can define your own logic and initialize the values as you wish. If you want to read a specific item before the user selected it, you can use the method GetItemAt(index) for the DataSource of the LoopingList. You can also find detailed looping list examples in our Demo application, available in the installation package.

I hope this information will be useful. However, if you would like to implement a different scenario, I would kindly like to ask you to share some more details on it, so I could assist you further.

Greetings,
Todor
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Perry
Top achievements
Rank 1
answered on 16 Dec 2011, 09:07 AM
Hi Todor,

Thanks for the quick response.  It never occurred to me that I should initialize the Radloopinglist in the data source.  I didn't see in the documentation that two event handlers were fired during initialization of the list.  When I looked (again), I couldn't figure out how to do what I wanted,  This is all that I could find for the methods that you mentioned.

-------------
LoopingListDataSource is fully virtualized which is why data items are created in the ItemNeeded event handler. A data item is created only if it is going to be visualized. 


The basic LoopingListDataItem supports only a text property. In order to add more properties users need to inherit from LoopingListDataItem and add the necessary information.

Then they can simply create an instance of their custom data item in the ItemNeeded event handler.

If the view port of the looping list is not big enough to display all of the data, which is almost always the case, users need to subscribe to the ItemUpdated event. ItemUpdated is called whenever the looping list needs to display new data, that is, data that is not visible at the moment, but that will be visualized shortly. For example when the looping list scrolls the items from the inertia caused by a user flick, the ItemUpdated event will be fired for items that will be visualized next. The arguments in the event handler provide the data item that has to be visualized and an index that corresponds to the real data record in the original data source. Users are expected to update the data item with the real data from their own data source. A code snippet will best illustrate this:

--------------------

I'm not sure that explains what I need to do.  To clarify what I need, I have a RadLoopingList (which i've set up with a datasource) that cycles through 0-9, simple integers (yes, I know it's displayed as text).  Upon startup, (initialization) I want a specific number to show on the list, it could be 3, 4,5, whatever, it will come from a variable somewhere.  Is this possible with the RadLoopingList?

A question about the description for ItemUpdated, how do you subscribe to that event? Can you provide some example code to illustrate how this should be used?

Another question, which may not be as significant, what does 'fully virtualized' mean?  Is this a c# concept?  I'm new with c#.

-Regards,
Perry
0
Todor
Telerik team
answered on 19 Dec 2011, 05:24 PM
Hi Perry,

Virtualization is actually not only a C# concept, but a concept in computing in general. In basic, it is the creation of a virtual (rather than actual) version of the data. In RadLoopingList the data comes from a LoopingListDataSource and the LoopingList contains the virtual containers for the data. In your scenario, you have 10 items, but the virtual containers are less. That means that upon initialization the containers that are needed (i.e. ItemNeeded is fired) are created so that they fill the screen of the device and their content is updated (i.e. ItemUpdated is fired). When the flick gesture occurs the same containers are used to represent the new data and only their content is updated (only the ItemUpdated is fired). Having in mind this you can create your logic for these two events. For example, for the digits from 0 to 9, starting from the value of a variable named startValue, the event handlers could look like this:


void dataSource_ItemNeeded(object sender, LoopingListDataItemEventArgs e)
{
    e.Item = new LoopingListDataItem();
}
 
void dataSource_ItemUpdated(object sender, LoopingListDataItemEventArgs e)
{
    e.Item.Text = ((e.Index + startValue) % 10).ToString();
}


And here is how you create a data source with 10 items and subscribe for the events:

LoopingListDataSource dataSource = new LoopingListDataSource(10);
dataSource.ItemNeeded += new EventHandler<LoopingListDataItemEventArgs>(dataSource_ItemNeeded);
dataSource.ItemUpdated += new EventHandler<LoopingListDataItemEventArgs>(dataSource_ItemUpdated);


If you want a specific item from the list to be selected before the user has tapped on it, you just have to set the SelectedIndex property of the RadLoopingList after you initialize it.

I hope this will help you. If you have any other questions, don't hesitate to write us back.

All the best,
Todor
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
jasonxz
Top achievements
Rank 1
answered on 10 Sep 2012, 08:51 PM
Todor,

In the previous post, you stated that to select an item in the LoopingList for the user, just set the SelectedIndex property of the LoopingList.  I am attempting to do that through Two-Way DataBinding.  The selecting is working fine, but the problem I'm having is that the selected item doesn't move into the viewport.  If I manually scroll, I can see that the appropriate item is selected, but I can't figure out how to make that item automatically visible.
0
Todor
Telerik team
answered on 11 Sep 2012, 08:50 AM
Hello Jason,

Thank you for contacting us.

The SelectedIndex is used exactly for the selection and it is not supposed to make the SelectedItem visible. In order to do this, you need to call the BringIntoView method after the Looping list is loaded:
loopingList.Loaded += this.OnLoopingListLoaded;
And here is the OnLoopingListLoaded:
void OnLoopingListLoaded(object sender, RoutedEventArgs e)
{
    loopingList.BringIntoView(loopingList.SelectedIndex);
}
I hope this information helps. Let me know if you need additional assistance.

Greetings,
Todor
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
jasonxz
Top achievements
Rank 1
answered on 13 Sep 2012, 03:30 AM
Thank you Todor for your response.
The problem with the solution you have provided is that, when the Loaded event fires for the LoopingList, I haven't created the LoopingListDataSource, yet.
What I'm doing is retrieving the data on a background thread, so the UI actually loads before the data is applied to it.  So, when the data arrives, I create the LoopingListDataSource, apply it to the LoopingList and set the SelectedIndex.
So, I assume I need to make a call between setting the LoopingList's DataSource and the SelectedIndex.  I have no idea what that is, though.
Can you help?
0
Todor
Telerik team
answered on 13 Sep 2012, 07:41 AM
Hello Jason,

The call you mean is the BringIntoView method. Since the data is not loaded when the LoopingList's Loaded event is fired, you can use the LoopingList's SelectedIndexChanged Event and call the BringIntoView on Dispatcher's BeginInvoke:
private void OnLoopingListSelectedIndexChanged(object sender, EventArgs e)
{
    this.Dispatcher.BeginInvoke(() =>
        {
            this.loopingList.BringIntoView(this.loopingList.SelectedIndex);
        });
}
I hope this information helps. Let me know if you need additional assistance.

Greetings,
Todor
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

0
jasonxz
Top achievements
Rank 1
answered on 18 Sep 2012, 11:22 AM
It seems to be working, now.
Thanx.
Tags
LoopingList
Asked by
Perry
Top achievements
Rank 1
Answers by
Todor
Telerik team
Perry
Top achievements
Rank 1
jasonxz
Top achievements
Rank 1
Share this question
or