using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ListViewControl
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();

			InitInstance();
		}

		private void InitInstance()
		{
			string curDir = Environment.CurrentDirectory;
			DirectoryInfo di = new DirectoryInfo(curDir);
			FileInfo[] files = di.GetFiles();

			UpdateListView(files);

			listView.View = View.Details;
		}

		private void UpdateListView(FileInfo[] files)
		{
			listView.BeginUpdate();

			listView.Columns.Clear();
			listView.Items.Clear();

			listView.Columns.Add("파일명", 200, HorizontalAlignment.Center);
			listView.Columns.Add("크기", 80, HorizontalAlignment.Center);
			listView.Columns.Add("생성일", 150, HorizontalAlignment.Center);
			listView.Columns.Add("편집일", 150, HorizontalAlignment.Center);

			foreach (var file in files)
			{
				ListViewItem item = new ListViewItem(file.Name);
				item.SubItems.Add(file.Length.ToString());
				item.SubItems.Add(file.CreationTime.ToString());
				item.SubItems.Add(file.LastWriteTime.ToString());

				listView.Items.Add(item);
			}
			
			listView.EndUpdate();
		}

		private void detailButton_CheckedChanged(object sender, EventArgs e)
		{
			listView.View = View.Details;
		}

		private void listButton_CheckedChanged(object sender, EventArgs e)
		{
			listView.View = View.List;
		}

		private void tileButton_CheckedChanged(object sender, EventArgs e)
		{
			listView.View = View.Tile;
		}
	}
}
