Getting Started with ListView

3 posts, 1 answers
  1. Walter
    Walter avatar
    4 posts
    Member since:
    Jul 2015

    Posted 11 Jul 2019 Link to this post

     

    Hi everyone!

    I'm trying to reproduce the example for ListView shown in

    https://docs.telerik.com/devtools/winforms/controls/listview/getting-started

    But instead of using a fixed DataTable, I'm connecting to a database. As I return a DataTable, everything was going ok until I found the word "MusicCollectionDataSet.SongsDataTableRow" and for example the line MusicCollectionDataSet.SongsDataTableRow songRow = row.Row as MusicCollectionDataSet.SongsDataTableRow; but as I have changed the DataSource to a DataTable from the Database, I don't know what is the script to replace those lines.

    I attached an image. Please Help. Thanks in advance.

     

    Regards,

    Walter

  2. Answer
    Nadya
    Admin
    Nadya avatar
    341 posts

    Posted 16 Jul 2019 Link to this post

    Hello Walter,

    MusicCollectionDataSet is an auto generated class when making use of the MusicCollection.mdb file. If you want to use a Datatable you should access the rows as shown in the following code snippet:
    private void radListView1_VisualItemFormatting(object sender, ListViewVisualItemEventArgs e)
    {
        if (this.radListView1.ViewType == Telerik.WinControls.UI.ListViewType.IconsView && e.VisualItem.Data.DataBoundItem != null)
        {
            DataRowView row = e.VisualItem.Data.DataBoundItem as DataRowView;
            var songRow = row.Row as DataRow;
            string albumName = songRow["AlbumName"].ToString();
            string songName = songRow["SongName"].ToString();
     
            e.VisualItem.Text = "<html> " + songName + "<br> " + albumName + "</span>";
        }
    }
     
    private void radListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
    {
     
        DataRowView row = e.Item.DataBoundItem as DataRowView;
        var songRow = row.Row as DataRow;
        e.Item.Image = (Image)songRow["Image"];
    }

    I hope this helps. Should you have any other questions, I will be glad to help.

    Regards,
    Nadya
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Walter
    Walter avatar
    4 posts
    Member since:
    Jul 2015

    Posted 16 Jul 2019 in reply to Nadya Link to this post

    Hello Nadya,

    Thank you very much, that is the simple code replacement I was looking for.

     

    Regards,

    Walter

Back to Top