c# - Why doesn't my ListView show Details view properly? -
so, i've got list view, indicated question title. i've got 2 columns set up: name , date modified. these added in designer, here's code emitted designer reference:
// lstfiles this.lstfiles.columns.addrange(new system.windows.forms.columnheader[] { this.clmname, this.clmdate}); // ... // clmname this.clmname.text = "name"; this.clmname.width = 105; // clmdate this.clmdate.text = "modified"; this.clmdate.width = 128;
in designer, looks beautiful.
the list items tiny subclass of listviewitem extracts metadata file (in case, date modified), , adds sub-item itself:
class galleryitem : listviewitem { public string file; public datetime datemodified; public galleryitem(string file) : base(path.getfilenamewithoutextension(file)) { this.imagekey = path.getextension(file); file = file; datemodified = system.io.file.getlastwritetime(file); this.subitems.add(datemodified.tostring()); } }
to add items list, this:
lstfiles.beginupdate(); lstfiles.clear(); foreach (string f in files) { listviewitem lvi = new galleryitem(f); lvi.group = lstfiles.groups["grpfiles"]; //this varries //omitted: check/add icon list lstfiles.items.add(lvi); } lstfiles.endupdate();
so, works great large icon view, etc:
however, breaks down on details view:
there are items in list (there's scroll bar). if click in column under red arrow (added in paint), you'll select item (the upper-right area image preview), won't see selected.
in summary, doing wrong?
i whipped sample test this:
using system; using system.windows.forms; static class program { [stathread] static void main() { application.enablevisualstyles(); application.setcompatibletextrenderingdefault(false); var g1 = new listviewgroup("group 1"); var g2 = new listviewgroup("group 2"); application.run(new form { controls = { new listview { dock = dockstyle.fill, groups = { g1, g2 }, view = view.details, //columns = { "first", "second" }, items = { new listviewitem { text = "one", group = g1, subitems = { "1" } }, new listviewitem { text = "two", group = g2, subitems = { "2" } }, new listviewitem { text = "three", group = g2, subitems = { "3" } }, }, }, }, }); } }
you notice duplicates problem. if uncomment line creates columns works. suggests columns don't exist.
and while typing answer popped head:
you calling listview.clear
instead of listview.items.clear
removing columns in code.
Comments
Post a Comment