I'm making a WPF app that implements a folder explorer.
And I want to add a new folder item to the top of the folder list view when the new folder button is pressed.
So I put a code that adds a sortdirection to sort by date, folder, and filename.
However, although the new folder is added to the top, there is a problem that the sort order of existing items is changed.
So, I would like to know how to make the existing items are sorted on top while new items are added. I know it is possible by using customsort, but it is difficult to implement with my skills.
Can anyone help me?
Below is the function code to add a new folder.
private void LocalNewFolder(int set_flag)
{
if (set_flag > 2) return;
if (uiList_textbox[set_flag - 1].Text == "") return;
var str_newfolder = "";
NewFolderInputBox Local_Mk_NewFolder = new NewFolderInputBox();
if (Local_Mk_NewFolder.ShowDialog() == true)
{
str_newfolder = Local_Mk_NewFolder.Text_NewFolder.Text;
if (str_newfolder == "")
return;
}
else
{
return;
}
string path_newfolder = uiList_textbox[set_flag - 1].Text + "\\" + str_newfolder;
//string path_newfolder = this.line_set1_local.Text + "\\" + str_newfolder;
if (!Directory.Exists(path_newfolder))
{
Directory.CreateDirectory(path_newfolder);
}
else
{
return;
}
var folderdate = Directory.GetLastWriteTime(path_newfolder);
if (set_flag == 1)
{
source_Local_path_all1.Insert(0, new Local_path_all1()
{
local_all_date = folderdate,
local_all_extension = "folder",
local_all_filename = str_newfolder,
local_all_size = "",
local_all_src = "Resources/icon_folder.png"
});
this.list_set1_local_all.Items.SortDescriptions.Clear();
this.list_set1_local_all.Items.SortDescriptions.Add(new SortDescription("local_all_date", ListSortDirection.Descending));
this.list_set1_local_all.Items.SortDescriptions.Add(new SortDescription("local_all_extension", ListSortDirection.Descending));
this.list_set1_local_all.Items.SortDescriptions.Add(new SortDescription("local_all_filename", ListSortDirection.Ascending));
this.list_set1_local_all.Items.Refresh();
}
else if (set_flag == 2)
{
source_Local_path_all2.Insert(0, new Local_path_all2()
{
local_all_date = folderdate,
local_all_extension = "folder",
local_all_filename = str_newfolder,
local_all_size = "",
local_all_src = "Resources/icon_folder.png"
});
this.list_set2_local_all.Items.SortDescriptions.Clear();
this.list_set2_local_all.Items.SortDescriptions.Add(new SortDescription("local_all_date", ListSortDirection.Descending));
this.list_set2_local_all.Items.SortDescriptions.Add(new SortDescription("local_all_extension", ListSortDirection.Descending));
this.list_set2_local_all.Items.SortDescriptions.Add(new SortDescription("local_all_filename", ListSortDirection.Ascending));
this.list_set2_local_all.Items.Refresh();
}
}