I could need some advice:
See picture 0.png how my tree looks:
Dokuments (this is a root item)
+--#inbox
+--testdir
after doing drag&drop action I need to refresh the counter in column 1. my hope was doing a "RefreshObject" on the tree model (I did many tries of other methods with even worse results).
After that refreshing I get the result seen in picture 1.png
Dokuments (this is a root item)
+--#inbox
+--testdir
+--testdir
there appears another "testdir" which is the same model as the original testdir. More drag&drops do not make more items to appear, but the second one is even too much...
seems like I found the solution myself:
the model is based on the MyFilesystemInfo from the demo projects.
The subdirectories are created when calling GetFilesystemInfos.
But another call creates different objects, so they are inserted into the tree very correctly!
the solution is to extend the model to keep the files and dirs and enable a force reread of the directory.
private List<MyFileSystemInfo> files = new List<MyFileSystemInfo>();
private List<MyFileSystemInfo> subdirs = new List<MyFileSystemInfo>();
private List<MyFileSystemInfo> temp = new List<MyFileSystemInfo>();
public IEnumerable GetFileSystemInfos( bool DirsOnly, bool ExcludeDotDirs, bool forceReload ) {
if( (subdirs.Count == 0 && files.Count == 0) || forceReload ) {
if( IsDirectory ) {
try {
// hier sind alle drin, beim forceReload werden alle entfernt, die noch da sind...
temp = subdirs.Concat( files ).ToList();
foreach( FileSystemInfo x in AsDirectory.GetFileSystemInfos() ) {
MyFileSystemInfo myX = new MyFileSystemInfo( x );
temp.Remove( myX );
if( x is DirectoryInfo ) {
if( !ExcludeDotDirs || !x.Name.StartsWith( "." ) ) {
if( !subdirs.Contains( myX ) )
subdirs.Add( myX );
}
}
else {
if( !files.Contains( myX ) )
files.Add( myX );
}
}
foreach( MyFileSystemInfo mfi in temp ) {
if( mfi.IsDirectory )
subdirs.Remove( mfi );
else
files.Remove( mfi );
}
}
catch( Exception Ex ) {
ReadErrors += Ex.Message + "\r\n";
}
}
}
if( DirsOnly )
return subdirs;
else
return subdirs.Concat(files);
}
by now the tree and the model work as expected.
thank you for your attention ;-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I could need some advice:
See picture 0.png how my tree looks:
Dokuments (this is a root item)
+--#inbox
+--testdir
after doing drag&drop action I need to refresh the counter in column 1. my hope was doing a "RefreshObject" on the tree model (I did many tries of other methods with even worse results).
After that refreshing I get the result seen in picture 1.png
Dokuments (this is a root item)
+--#inbox
+--testdir
+--testdir
there appears another "testdir" which is the same model as the original testdir. More drag&drops do not make more items to appear, but the second one is even too much...
What am I doing wrong?
seems like I found the solution myself:
the model is based on the MyFilesystemInfo from the demo projects.
The subdirectories are created when calling GetFilesystemInfos.
But another call creates different objects, so they are inserted into the tree very correctly!
the solution is to extend the model to keep the files and dirs and enable a force reread of the directory.
by now the tree and the model work as expected.
thank you for your attention ;-)