File view

File View (list view and tree view) in C#

Table of contents:-

1) Introduction

2) Interface

3) Coding/Construction

4) Working/Running

Introduction:-

The File View displays local/network drives and removable media.  Visibility of the File View may be toggled by selecting File View in the View menu. A list of file extensions can be specified and for each file extension a renderer. In conjunction with the upload module, the links in the attachments table can be replaced by links to view the files online.

Tools: Visual Studio 2010 and c#

Interface:-

à If the button is pressed, the File View pane will be split horizontally with the upper pane showing the default file tree view and the lower pane showing the contents of the selected Folder.

List view and Tree view:-

List View is another control that displays lists of information. It represents data relationally as items and sub items. The data can be represented in a variety of formats that include a multi-column grid and large or small icons to represent item data. Also, images and check boxes can adorn the control.

The Tree View control provides a tree-like view of hierarchical data as its user interface. Underneath, its programming model is based on the familiar tree structure consisting of parent nodes and child nodes. Each node is implemented as a Tree Node object that can in turn have its own Nodes collection.

Code:-

 namespace WindowsFormsApplication1

{

Public partial class Form1 : Form

{

Public Form1()

{

InitializeComponent();

}

 

Private void Form1_Load(object sender, EventArgs e)

{      }

Get all the directories in tree view:-

Private void button1_Click(object sender, EventArgs e)

{

String [] ids = Directory.GetLogicalDrives ();

For each (String id in ids)

{

treeView1.Nodes.Add (id);

}

}

After select tree view icon directories will show in list view:-

private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)

{

listView1.Clear();

 

listView1.LargeImageList = imageList2;

listView1.SmallImageList = imageList2;

listView1.StateImageList = imageList2;

try

{

String[] dirs = Directory.GetDirectories(treeView1.SelectedNode.Text);

String[] dir = Directory.GetFiles(treeView1.SelectedNode.Text);

foreach (String S in dirs)

{

listView1.Items.Add(S, 0);

treeView1.SelectedNode.Nodes.Add(S);

}

foreach (String S in dir)

{

listView1.Items.Add(S, 0);

treeView1.SelectedNode.Nodes.Add(S);

}

}

catch (Exception E)

{

MessageBox.Show(“no further directory”);

}

}

Menu strip code:-

private void largeToolStripMenuItem_Click(object sender, EventArgs e)

{

listView1.View = View.LargeIcon;

}

private void smallToolStripMenuItem_Click(object sender, EventArgs e)

{

listView1.View = View.SmallIcon;

}

private void listToolStripMenuItem_Click(object sender, EventArgs e)

{

listView1.View = View.List;

}

 

private void existToolStripMenuItem_Click(object sender, EventArgs e)

{

this.Dispose();

}

 

private void button2_Click(object sender, EventArgs e)

{

this.Dispose();

}

 

private void listView1_MouseClick(object sender, MouseEventArgs e)

{

}

}

}