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

event for tracking selected item index with mouse and keyboard

7 Answers 121 Views
Carousel
This is a migrated thread and some comments may be shown as answers.
Bill
Top achievements
Rank 1
Bill asked on 10 Dec 2009, 11:53 AM

What event of the rad Carousel can I use to track the currently selected item’s index when it changes?

 

I need to track the selected item’s index in the Carousel control for both the mouse and keyboard whenever the Carousel item is changed to another item. For example, just like in a list box, the selected item changed event is raised letting you read the currently selected item’s index.

 

 

I noticed that the Carousel control has buttons that you can move to next, previous, last, first, etc. but there are no button click events for those buttons  on the Carousel control itself.

 

So again, I just need a way to perform the following task using a Carousel control event:

 

1.        The currently selected item changes to a new item

2.  I then can get the new selected item’s index of the Carousel control

 

 

And again, I need to do this task no matter if it is the keyboard, the mouse, the mouse wheel, the click of the mouse, etc. I just need an event to help me get the currently selected item’s index.

 

Note: I am not using the most recent version of the telerik controls. I think I am one or two versions prior.

 

Help!

 

Bill

7 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 10 Dec 2009, 03:04 PM
Hello Bill,

 Could you please refer to the last post of this forum thread which contains the answer to your question.

All the best,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Bill
Top achievements
Rank 1
answered on 10 Dec 2009, 03:29 PM

Thank you for the reply. I am using vb.net and have this code now which compiles with no errors. However, the indexof method keeps returning -1 and cannot find the currently selected carouselItem  in the Me.rdCarousel.Items list. What do I need to do in order to find the index of the currently selected carouselItem?

Private Sub RadCarouselPanel_TopContainerChanged(ByVal sender As Object, ByVal e As RoutedEventArgs)
            Dim carouselPanel = CType(sender, RadCarouselPanel)
            Dim carouselItem = CType(carouselPanel.TopContainer, CarouselItem)

            If Not carouselItem Is Nothing Then

                If Me.rdCarousel.Items.IndexOf(carouselItem) > -1 Then
                    Me._currentIndex = Me.rdCarousel.Items.IndexOf(carouselItem)
                End If
            End If

        End Sub

Bill

0
Bill
Top achievements
Rank 1
answered on 12 Dec 2009, 06:06 PM

Can someone please answer my question? It has been 2 days now and I really could use some help.

Here is the code below in C#.NET in case it will help clarify my problem.

This line of syntax:

            this._currentIndex = this.rdCarousel.Items.IndexOf(carouselItem);

always returns -1 but in reality, the rdCarousel.Items.Count is 6.

I need to get the current index of the currently selected Carousel item and store it in my _currentIndex class member.

What do I need to do to accomplish this task? What am I doing incorrectly?

Here is the code...

private void RadCarouselPanel_TopContainerChanged(object sender, RoutedEventArgs e)
{
    var carouselPanel = (RadCarouselPanel)sender;
    var carouselItem = (CarouselItem)carouselPanel.TopContainer;
   
    if ((carouselItem != null)) {

// assign current index of the currently selected Carousel item
// to my local class member
       
        if (this.rdCarousel.Items.IndexOf(carouselItem) > -1) {
            this._currentIndex = this.rdCarousel.Items.IndexOf(carouselItem);
        }
       
    }
}

Bill

0
Milan
Telerik team
answered on 14 Dec 2009, 10:22 AM
Hello Bill,

You should make a minor adjustment to your code to make it work:

'replace 
Me.rdCarousel.Items.IndexOf(carouselItem)
'with
Me.rdCarousel.Items.IndexOf(carouselItem.Item)

The Item property will return the data item that is associated with the respective CarouselItem. Since IndexOf works with data items carouselItem.Item should be used instead of carouselItem.

Hope this helps.

Regards,

Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Bill
Top achievements
Rank 1
answered on 14 Dec 2009, 11:13 AM
Thank you for the reply. I do not have a .Item property. Here is the error that I get:

'Item' is not a member of 'Telerik.Windows.Controls.CarouselItem'. NavigationControlPanel. 154 DataSharkSoftware.EZ
I am not using the latest version of the control. I think I am using the april 2009 release. What property should I use instead of the .Item? Is there another way I can accomplish the same thing?

Bill
0
Milan
Telerik team
answered on 14 Dec 2009, 01:06 PM
Hi Bill,

Yes, the Item property was introduced with Q3. Could you please try to use the DataItem property instead.If that does not work as well, could you please specify the exact version of RadControl for WPF that you are using? You can easily check this by opening the properties window of any of our dlls and navigating to the Details tab.


Sincerely yours,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Bill
Top achievements
Rank 1
answered on 14 Dec 2009, 05:17 PM
I am using version 2009.1.0312.35.

Thanks for your time and efforts,

B
Tags
Carousel
Asked by
Bill
Top achievements
Rank 1
Answers by
Milan
Telerik team
Bill
Top achievements
Rank 1
Share this question
or