Recognizing the value of bonded control in carousel

7 posts, 0 answers
  1. Hamid
    Hamid avatar
    20 posts
    Member since:
    May 2009

    Posted 17 Aug 2011 Link to this post

    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.
  2. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 17 Aug 2011 Link to this post

    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 >>

  3. UI for WPF is Visual Studio 2017 Ready
  4. Hamid
    Hamid avatar
    20 posts
    Member since:
    May 2009

    Posted 17 Aug 2011 Link to this post

    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.
  5. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 17 Aug 2011 Link to this post

    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 >>

  6. Hamid
    Hamid avatar
    20 posts
    Member since:
    May 2009

    Posted 17 Aug 2011 Link to this post

    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());
           }
  7. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 17 Aug 2011 Link to this post

    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 >>

  8. Hamid
    Hamid avatar
    20 posts
    Member since:
    May 2009

    Posted 17 Aug 2011 Link to this post

    It worked!
    Thank you very much.
    Have a good time.
Back to Top
UI for WPF is Visual Studio 2017 Ready