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

Programmatic Data Binding

4 Answers 79 Views
Carousel
This is a migrated thread and some comments may be shown as answers.
Tony
Top achievements
Rank 1
Tony asked on 13 Feb 2015, 02:26 AM
Hi,

Trying to follow the example in your documentation of connecting the carousel to a dataset 

this.MyCarousel.ItemsSource = dsCarousel(); //My named dataset


I've created a dataset object using the 'Data Sources' option in VS2012. When I set the itemsource to the dataset name it's telling me datasource is a type but being used as a variable, which I understand.


this.RadCarousel1.ItemsSource = GetDataTable();

radCarousel1.DataMember = "Orders";
radCarousel1.ItemsSource = dataSet;


//MY CODE EXAMPLE BELOW

namespace WPFTest
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            this.MyCarousel.ItemsSource = dsCarousel();

        }
    }
}


What I don't understand is how exactly am I to interpret the example of assigning the dataset per the documentation? I can test and see data fill the dataset object using TableAdapter Config Wizard so I know it's connecting. But do I have to create this dataset completely in code to use it or am I missing or not understanding something very obvious. I'm new to windows programming and especially using WPF controls so I'm just trying to find my way here. Let me know if I've made sense at all?

Thanks in advance.

Tony








4 Answers, 1 is accepted

Sort by
0
Boris
Telerik team
answered on 17 Feb 2015, 03:40 PM
Hello Tony,

In order to get the currently selected item you can use the SelectionChanged event of RadCarousel like so:

void radCarousel_SelectionChanged(object sender, SelectionChangeEventArgs e)
        {
            var selectedItem = e.AddedItems[0] as DataRowView;
 
            if (selectedItem != null)
            {
                // Do something with the SelectedItem
            }
             
        }

I attached a sample project that demonstrates how to set initially the selected item and that it will trigger the mentioned event.


I hope this helps.

Regards,
Boris
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Tony
Top achievements
Rank 1
answered on 17 Feb 2015, 06:05 PM
Boris,

Thank you for your complete and thorough response. Fortunately I was able to get the data connect to happen and while your example was great in showing another approach. The last item of concern for me is trying to ascertain the specific data element of any particular carousel item clicked. Basically I have a carousel connecting to a database driven dataset pulling two data elements chartname and colid. While both do populate the carousel and the correct number of carousel items do render, I'm stuck on how to get the specific colid so that I can pull the correct item from the dataset,if that makes sense. See code snippets below.


public MainWindow()
        {
            InitializeComponent();

            this.MyCarousel.ItemsSource = getData();
        }


        public  DataTable getData()
        {
            string connectionString = "Data Source=PRD1IMXSQL01.amr.corp.intel.com,3180;Initial Catalog=IMX_310;Integrated Security=True";
            DataSet dss = new DataSet();
            SqlConnection connection = new SqlConnection(connectionString);
            string sql = "";
            sql = "SELECT DISTINCT ChartName, COLID FROM ChartGroup WHERE (obsolete = 0) AND (GroupName = N'2014 Q4 vs Q2v1 CNL (600 MHz)')";
            SqlDataAdapter adapter = new SqlDataAdapter(sql, connectionString);
            adapter.Fill(dss);
            DataTable dt = dss.Tables[0];
            return dt;
        }


        private void MyCarousel_MouseUp(object sender, MouseButtonEventArgs e)
        {

            //WANT TO DISPLAY COLID data element of clicked carousel item in text box
            txtClicked.Text = {display colid data element here}
        }


0
Boris
Telerik team
answered on 20 Feb 2015, 09:29 AM
Hello Tony,

In your case the ItemsSource property of RadCarousel is bound to a DataTable, which means that the selected item will be of type DataRowView. As demonstrated in my previous reply you can get that item through the SelectionChanged event and cast it to DataRowView type the exact implementation of how to get the desired data from that item is up to you.

I hope this helps.

Regards,
Boris
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Tony
Top achievements
Rank 1
answered on 20 Feb 2015, 05:13 PM
Actually the post at this link answered my question perfectly.

Thanks!

http://www.telerik.com/forums/recognizing-the-value-of-bonded-control-in-carousel#_bVRH6n140KkcfpId_B0_Q
Tags
Carousel
Asked by
Tony
Top achievements
Rank 1
Answers by
Boris
Telerik team
Tony
Top achievements
Rank 1
Share this question
or