Failing to display items programatically added to a ListView that has columns

2 posts, 0 answers
  1. Wayne
    Wayne avatar
    36 posts
    Member since:
    May 2013

    Posted 08 Jan 2014 Link to this post

    I'm sure I'm doing something wrong here, but I followed the documentation and it still doesn't seem to be working.  All I get is a blank item in my ListView.  Here's the code to recreate my issue.  The columns I've added to the control at design-time are named exactly what they indicate below.

    private void LoadFiles(DirectoryInfo dir)
            {
                FileInfo[] files = dir.GetFiles();
     
                this.lvFiles.Items.Clear();
                this.lvFiles.Items.BeginUpdate();
     
                foreach (FileInfo file in files)
                {
                    Telerik.WinControls.UI.ListViewDataItem listItem = new Telerik.WinControls.UI.ListViewDataItem();
                     
                    this.lvFiles.Items.Add(listItem);
                     
                    listItem["Name"] = file.Name;
                    listItem["DateTime"] = file.LastWriteTime.ToString();
                    listItem["Type"] = "file";
                    listItem["Size"] = UtilLib.FileIO.ToByteString(file.Length);
                    listItem["Uploaded By"] = "Wango";
                    listItem.Tag = file;               
                }
                this.lvFiles.Items.EndUpdate();
            }
  2. Dimitar
    Admin
    Dimitar avatar
    1404 posts

    Posted 09 Jan 2014 Link to this post

    Hi Wayne,

    Thank you for contacting Telerik support.

    The only thing that appears to be missing is that you should set the ViewType to DetailsView in order to view the columns:
    radListView1.ViewType = Telerik.WinControls.UI.ListViewType.DetailsView;

    For convenience using your code I have created and attached a small sample project.

    Do not hesitate to contact us if you have other questions.

    Regards,
    Dimitar
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top