public FileViewer(MainForm mainForm) { m_mainForm = mainForm; // create a standard WinForms ListView control m_listView = new ListView(); m_listView.Dock = DockStyle.Fill; m_listView.Text = "File Viewer"; m_listView.BackColor = SystemColors.Window; m_listView.SmallImageList = ResourceUtil.GetImageList16(); m_listView.AllowColumnReorder = true; // create an adapter to drive the ListView control m_listViewAdapter = new ListViewAdapter(m_listView); m_fileListView = new FileListView(); }
private FileListView<TableData> CreateListView() { var listview = new FileListView<TableData>(); listview.Name = "listview"; listview.HideSelection = false; listview.View = View.Details; listview.FullRowSelect = true; listview.ContextMenuStrip = ListViewContextMenu; listview.Dock = DockStyle.Fill; ColumnHeader headerName = new ColumnHeader(); headerName.Name = "name"; headerName.Text = "name"; listview.Columns.Add(headerName); ColumnHeader headerSize = new ColumnHeader(); headerSize.Name = "size"; headerSize.Text = "size"; listview.Columns.Add(headerSize); ColumnHeader headerExt = new ColumnHeader(); headerExt.Name = "ext"; headerExt.Text = "ext"; listview.Columns.Add(headerExt); ColumnHeader headerTags = new ColumnHeader(); headerTags.Name = "tags"; headerTags.Text = "tags"; listview.Columns.Add(headerTags); ColumnHeader headerComment = new ColumnHeader(); headerComment.Name = "comment"; headerComment.Text = "comment"; listview.Columns.Add(headerComment); ColumnHeader headerCreationTime = new ColumnHeader(); headerCreationTime.Name = "creationtime"; headerCreationTime.Text = "creationtime"; listview.Columns.Add(headerCreationTime); ColumnHeader headerLastWriteTime = new ColumnHeader(); headerLastWriteTime.Name = "lastwritetime"; headerLastWriteTime.Text = "lastwritetime"; listview.Columns.Add(headerLastWriteTime); listview.LabelFunc = (data, name) => { string ret = string.Empty; switch(name){ case "name": ret = data.name; break; case "ext": ret = data.ext; break; case "size": ret = data.size.ToString(); break; case "tags": ret = data.TagsToString(); break; case "comment": ret = data.comment; break; case "creationtime": ret = data.creationtime.ToString("yyyy/MM/dd HH:mm:ss"); break; case "lastwritetime": ret = data.lastwritetime.ToString("yyyy/MM/dd HH:mm:ss"); break; } return ret; }; listview.ItemSelectionChanged += (sender, e) => { if (listview.mySel.Count > 0) { selectedIndexQueue.Enqueue(listview.mySel[0]); if (selectedIndexQueue.Count > 2) { selectedIndexQueue.Dequeue(); } ListViewItem item = listview.myCol[listview.mySel[0]]; detailview.Data = listview.getData(item); } }; listview.listViewItemComparer.SortFunc = (x, y, columindex) => { int result = 0; string columname = listview.Columns[columindex].Name; switch (columname) { case "name": result = string.Compare(x.name, y.name); break; case "size": result = x.size-y.size>0?1:-1; break; case "ext": result = string.Compare(x.ext, y.ext); break; case "comment": result = string.Compare(x.comment, y.comment); break; //case "tags": // result = string.Compare(x.tags, y.tags); // break; case "creationtime": result = DateTime.Compare(x.creationtime, y.creationtime); break; case "lastwritetime": result = DateTime.Compare(x.lastwritetime, y.lastwritetime); break; } return result; }; return listview; }