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

Recognizing the value of bonded control in carousel

6 Answers 69 Views
Carousel
This is a migrated thread and some comments may be shown as answers.
Hamid
Top achievements
Rank 1
Hamid asked on 17 Aug 2011, 11:32 AM
Hi, 
The following is my Xaml code:
<Window x:Class="RadControlsWpfApp1.MainWindow"
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                Title="MainWindow" Height="700" Width="900" Background="Black">
 
    <Grid>
        <Grid.Resources>
            <DataTemplate x:Key="customItemTemplate">
                <StackPanel>
                    <Image Source="{Binding Path=Country}" Height="150" HorizontalAlignment="Left" Margin="10,10,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="200" />
                    <Button Content="Show Details" Height="23" Name="btnDetail" Width="75" Foreground="White" Click="btnDetail_Click" />
                    <Label x:Name="ID" Content="{Binding Path=ID}"></Label>
                </StackPanel>
            </DataTemplate>
        </Grid.Resources>
        <telerik:RadCarousel x:Name="sampleRadCarousel" ItemTemplate="{StaticResource customItemTemplate}" Background="Transparent" GotFocus="sampleRadCarousel_GotFocus" />                            
    </Grid>
     
</Window>

I wanna show content of Lable (ID) when the user clicks to Button (btnDetail).
How can I do that?
Thanks for your helping.

6 Answers, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 17 Aug 2011, 12:22 PM
Hi Hamid,

 

You may get any item in RadCarousel cast it to your object and then you may access any properties you need. For example: you can get the Employee's Age of the SelectedItem in RadCarousel as follows:


private void RadButton_Click(object sender, RoutedEventArgs e)
     {
         var item = (this.carousel.SelectedItem as Employee).Age.ToString();
         MessageBox.Show("Selected employee is " + item + " years old");
     }



You may read more about RadCarousel/WPF in our online documentation, following this link.



All the best,
Vanya Pavlova
the Telerik team

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

0
Hamid
Top achievements
Rank 1
answered on 17 Aug 2011, 02:40 PM
Sorry, I use a dataset to fill my Carousel & there is no class like Employee in my project!
So, the codes that you mentioned aren't suitable to my project.
Please look at:

OleDbConnection oleCon = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=DataBase.mdb");
OleDbCommand oleComd = new OleDbCommand("Select * From tblMovie", oleCon);
DataSet dtst = new DataSet();
OleDbDataAdapter adpt = new OleDbDataAdapter();
oleCon.Open();
adpt.SelectCommand = oleComd;
adpt.Fill(dtst, "emp");
sampleRadCarousel.ItemsSource = dtst.Tables[0].DefaultView;

 In this way how can I access the selected Item's value?
Thanks again.
0
Vanya Pavlova
Telerik team
answered on 17 Aug 2011, 02:55 PM
Hi Hamid,

 


Since you are binding to DataRows you have to gather the information from this row relatively to the RadCarousel's SelectedItem as demonstrated in the following MSDN article



Best wishes,
Vanya Pavlova
the Telerik team

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

0
Hamid
Top achievements
Rank 1
answered on 17 Aug 2011, 03:37 PM
Thanks Vanya,
I tried so much and now I'm completely confused!
I saw MSDN article solution and tried to do that but in my project it returns Null.
Here is my code:

private void btnDetail_Click(object sender, RoutedEventArgs e)
       {
           object Obj = this.sampleRadCarousel.SelectedItem;
           DataRow Row = ((DataRowView)Obj).Row;
           MessageBox.Show("Selected ID is " + Row["ID"].ToString());
       }
0
Vanya Pavlova
Telerik team
answered on 17 Aug 2011, 03:52 PM
Hello Hamid,

 
I have just tested the behavior when the RadCarouselPanel is bound to a DataTable and the snipper above works correctly by my side. I am attaching you the application which I used for testing. You may also submit a new support ticket and attach your project where we can see what might be wrong.  


 

Kind regards,
Vanya Pavlova
the Telerik team

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

0
Hamid
Top achievements
Rank 1
answered on 17 Aug 2011, 04:17 PM
It worked!
Thank you very much.
Have a good time.
Tags
Carousel
Asked by
Hamid
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Hamid
Top achievements
Rank 1
Share this question
or