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

Getting Started with ListView

2 Answers 148 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Walter
Top achievements
Rank 1
Walter asked on 11 Jul 2019, 04:24 PM

 

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 Answers, 1 is accepted

Sort by
0
Accepted
Nadya | Tech Support Engineer
Telerik team
answered on 16 Jul 2019, 12:19 PM
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.
0
Walter
Top achievements
Rank 1
answered on 16 Jul 2019, 04:10 PM

Hello Nadya,

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

 

Regards,

Walter

Tags
ListView
Asked by
Walter
Top achievements
Rank 1
Answers by
Nadya | Tech Support Engineer
Telerik team
Walter
Top achievements
Rank 1
Share this question
or