This project is read-only.

simple ListView example

Feb 23, 2010 at 1:41 PM


first of all thanks for these nice controls! I'm building an application right now but have problems creating a ListView!
What I have so far is

        private void CreateListView()
            ListView listView = new ListView();
            listView.Margin = new Margin(16);
            listView.ItemHeight = 64;
            listView.ItemClicked += new EventHandler<ItemEventArgs>(listView_ItemClicked);
            foreach (string fileName in GetFileNames())
                FileItem item = new FileItem(fileName);

        void listView_ItemClicked(object sender, ItemEventArgs e)

Where GetFileNames() returns a List<string> and FileItem is

    public class FileItem : ListViewItem, ISelectable
        public FileItem(string title)
            : base()
            Label titleLabel = new Label();
            titleLabel.Text = title;
But the list isn't visible. What am I missing?
Mar 5, 2010 at 11:43 AM

Hi heliosdev,

did you try setting the Size of the FileItem in the constructor?

Size=new Size(Width,64);

Help me once, however I am not sure if this will do the trick here. you may also try to set the Margin of the titleLabel to 0 (new Margin(0)) so that the label gets automatically adjusted to the ListViewItem.




Mar 7, 2010 at 3:33 PM
Edited Mar 7, 2010 at 3:33 PM

Hi schaze,

yes, added

Size = new Size(0, 64);
titleLabel.Margin = new Margin(16); // 0 is the default margin

in the FileItem constructor and it works now!