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

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

1 Answer 88 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Hannah
Top achievements
Rank 2
Hannah asked on 08 Jan 2014, 06:04 PM
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();
        }

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 09 Jan 2014, 01:02 PM
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 >>
Tags
ListView
Asked by
Hannah
Top achievements
Rank 2
Answers by
Dimitar
Telerik team
Share this question
or