Programmatic Data Binding

5 posts, 0 answers
  1. Tony
    Tony avatar
    24 posts
    Member since:
    Sep 2014

    Posted 12 Feb 2015 Link to this post

    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








  2. Boris
    Admin
    Boris avatar
    276 posts

    Posted 17 Feb 2015 Link to this post

    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.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Tony
    Tony avatar
    24 posts
    Member since:
    Sep 2014

    Posted 17 Feb 2015 in reply to Boris Link to this post

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


  5. Boris
    Admin
    Boris avatar
    276 posts

    Posted 20 Feb 2015 Link to this post

    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.

     
  6. Tony
    Tony avatar
    24 posts
    Member since:
    Sep 2014

    Posted 20 Feb 2015 in reply to Boris Link to this post

    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
Back to Top
UI for WPF is Visual Studio 2017 Ready