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 (presumably because the data is stored in the files themselves). 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.
Any pointers would be greatly appreciated.
Please see my code (some previous attempts have been commented out):
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 (presumably because the data is stored in the files themselves). 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.
Any pointers would be greatly appreciated.
Please see my code (some previous attempts have been commented out):
// ListView1
string[] checkedINfileList = Directory.GetFiles("O:\\TestDaws\\CSDB\\CheckedIN");
foreach (string file in checkedINfileList)
{
FileInfo f = new FileInfo(file);
long fileSize = f.Length;
DateTime file_date = f.LastWriteTime;
string fileName = Path.GetFileName(file);
ListViewItem item = new ListViewItem(fileName);
listView1.Items.Add(item);
item.SubItems.Add(fileSize.ToString() + " Kb");
item.SubItems.Add(file_date.ToString());
}
//ListView2
string[] checkedOUTfileList = Directory.GetFiles("O:\\TestDaws\\CSDB\\CheckedOUT");
foreach (string file in checkedOUTfileList)
{
FileInfo f = new FileInfo(file);
long fileSize = f.Length;
DateTime file_date = f.LastWriteTime;
string fileName = Path.GetFileName(file);
ListViewItem item2 = new ListViewItem(fileName);
listView2.Items.Add(item2);
item2.SubItems.Add(fileSize.ToString() + " Kb");
item2.SubItems.Add(file_date.ToString());
//NEED TO ADD THE VALUE STORED IN THE 4TH COLUMN (POS 3) OF LISTVIEW1 IN HERE
//THE 4TH COLUMN IS POPULATED FURTHER DOWN THE CODE WITH THE BUTTON_2 CLICK EVEN HANDLER
}
}
//Check Out Button Click
public ListView.SelectedListViewItemCollection mySelectedItems;
private void button1_Click(object sender, EventArgs e)
{
mySelectedItems = listView1.SelectedItems;
string toDir ="O:\\TestDaws\\CSDB\\CheckedOUT";
string fromDir = "O:\\TestDaws\\CSDB\\CheckedIN";
if (mySelectedItems.Count > 0)
{
foreach (ListViewItem items in mySelectedItems)
{
try
{
File.Move(fromDir + "\\" + items.Text, toDir + "\\" + items.Text);
MessageBox.Show("Checking Out: \n" + items.Text);
listView2.Refresh();
//for (int i = 0; i < listView1.Items.Count; i++)
//{
// ListViewItem newList = new ListViewItem();
// if (listView1.Items[i].SubItems[3].ToString() != null)
// {
// string test = listView1.Items[i].SubItems[3].ToString();
// newList.SubItems.Add(test);
// }
//}
listView1.Items.Remove(items);
}
catch (Exception ex)
{
MessageBox.Show("Error" + ex);
}
}
}
}
//Add Note Button Click
public void button2_Click(object sender, EventArgs e)
{
mySelectedItems = listView1.SelectedItems;
if (textBox1.Text != null && mySelectedItems.Count > 0)
try
{
foreach (ListViewItem itemsForNote in mySelectedItems)
itemsForNote.SubItems.Add(textBox1.Text);
}
catch (Exception ex)
{
MessageBox.Show("Error" + ex);
}
else
{
MessageBox.Show("Please select DMs and write note in the box", "Forgotton Something?");
}
}
private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
{
}
//Remove Note
private void removeNoteToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
foreach (ListViewItem myItem in mySelectedItems)
myItem.SubItems.Remove(myItem.SubItems[3]);
}
catch (Exception ex)
{
MessageBox.Show("Error" + ex);
}