Hi,I have a Windows forms project with 2 tabs. Both tabs have a ListView control. The first tab shows the contents of one folder (Checked Out) and the other contains the contents of another folder (checked in).Despite my limited knowledge of c# (still learning) i've managed to make both ListView controls behave pretty much as i want them too.However, what i need to be able to do, is when i click the 'Check Out' button on tab 1, the selected files in the listView1 control are removed (along with the file in the checked in folder being moved to the checked out folder). Then the listView2 in the second tab should display the files that were moved. This, somewhat surprisingly, i have managed to do with some success. My first problem is that the listview2 in the second tab doesn't automatically refresh - so i effectively have to close the program and re-open it in order to see the updated listView2 with the new files. My second problem (and this has been doing my head in for hours) is this: I have 4 columns in my ListViews (name, size, date modified and notes). The first 3 colums come accross into my listView2 control without problem (because i'm not copying from one list to the other, the lists are just looking at a folder containing files - and the files are movin from one to the other). However, what i need is for the 'Notes' data which is stored in column 4 (index 3) in listView1 to come accross into listView2 when the data moves accross.I hope that's clear enough. Basically i don't know how to copy the column 4 data of one listView to column 4 of the other Listview.
Any pointers would be greatly appreciated.Please see my code (some previous attempts have been commented out). (Also, i know the code isn't very efficient ... i intend to clean it up later, but i'm always open to suggestions on improving my code).
002 | string [] checkedINfileList = Directory.GetFiles( "O:\\TestDaws\\CSDB\\CheckedIN" ); |
005 | foreach ( string file in checkedINfileList) |
007 | FileInfo f = new FileInfo(file); |
009 | long fileSize = f.Length; |
010 | DateTime file_date = f.LastWriteTime; |
011 | string fileName = Path.GetFileName(file); |
013 | ListViewItem item = new ListViewItem(fileName); |
015 | listView1.Items.Add(item); |
016 | item.SubItems.Add(fileSize.ToString() + " Kb" ); |
017 | item.SubItems.Add(file_date.ToString()); |
021 | string [] checkedOUTfileList = Directory.GetFiles( "O:\\TestDaws\\CSDB\\CheckedOUT" ); |
024 | foreach ( string file in checkedOUTfileList) |
026 | FileInfo f = new FileInfo(file); |
028 | long fileSize = f.Length; |
029 | DateTime file_date = f.LastWriteTime; |
030 | string fileName = Path.GetFileName(file); |
032 | ListViewItem item2 = new ListViewItem(fileName); |
034 | listView2.Items.Add(item2); |
035 | item2.SubItems.Add(fileSize.ToString() + " Kb" ); |
036 | item2.SubItems.Add(file_date.ToString()); |
051 | public ListView.SelectedListViewItemCollection mySelectedItems; |
053 | private void button1_Click( object sender, EventArgs e) |
055 | mySelectedItems = listView1.SelectedItems; |
057 | string toDir = "O:\\TestDaws\\CSDB\\CheckedOUT" ; |
058 | string fromDir = "O:\\TestDaws\\CSDB\\CheckedIN" ; |
060 | if (mySelectedItems.Count > 0) |
063 | foreach (ListViewItem items in mySelectedItems) |
067 | File.Move(fromDir + "\\" + items.Text, toDir + "\\" + items.Text); |
068 | MessageBox.Show( "Checking Out: \n" + items.Text); |
087 | listView1.Items.Remove(items); |
093 | MessageBox.Show( "Error" + ex); |
103 | public void button2_Click( object sender, EventArgs e) |
105 | mySelectedItems = listView1.SelectedItems; |
108 | if (textBox1.Text != null && mySelectedItems.Count > 0) |
112 | foreach (ListViewItem itemsForNote in mySelectedItems) |
113 | itemsForNote.SubItems.Add(textBox1.Text); |
118 | MessageBox.Show( "Error" + ex); |
123 | MessageBox.Show( "Please select DMs and write note in the box" , "Forgotton Something?" ); |
129 | private void contextMenuStrip1_Opening( object sender, CancelEventArgs e) |
135 | private void removeNoteToolStripMenuItem_Click( object sender, EventArgs e) |
141 | foreach (ListViewItem myItem in mySelectedItems) |
142 | myItem.SubItems.Remove(myItem.SubItems[3]); |
146 | MessageBox.Show( "Error" + ex); |