본문 바로가기

C#

c# winform listview

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
 
namespace ListViewTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.Load += Form1_Load;
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            SettingListView(listView1, GetCurrentDirectory());
        }
 
        private FileInfo[] GetCurrentDirectory()
        {
            string currDir = Environment.CurrentDirectory;
            DirectoryInfo di = new DirectoryInfo(currDir);
            FileInfo[] files = di.GetFiles();
 
            return files;
        }
 
        private void SettingListView(ListView listView, FileInfo[] files)
        {
            // Don't renew UI until the update ends;
            listView.BeginUpdate();
 
            listView.View = View.Details;
            listView.LargeImageList = imageList1;
            listView.SmallImageList = imageList1;
 
 
            foreach (var fi in files)
            {
                ListViewItem lvi = new ListViewItem(fi.Name);
                lvi.SubItems.Add(fi.Length.ToString());
                lvi.SubItems.Add(fi.LastWriteTime.ToString());
                lvi.ImageIndex = 0;// Image를 첫번째 column에 놓는다.
 
                listView.Items.Add(lvi);
 
            }
            listView.Columns.Add("파일명"200, HorizontalAlignment.Left);
            listView.Columns.Add("사이즈"70, HorizontalAlignment.Left);
            listView.Columns.Add("날짜"150, HorizontalAlignment.Left);
            listView.EndUpdate();
 
            this.Refresh();
        }
    }
}
 
cs

'C#' 카테고리의 다른 글

c# winform timer  (0) 2021.11.07
c# winform backgroundworker 스레드 중단/재개하기 코드  (1) 2021.11.06
c# winform chart(only for .net framework)  (0) 2021.11.06
c# winform drag & drop  (0) 2021.11.05
c# winform background worker 사용하기  (0) 2021.11.05