|
Hmm I'm not quite following sorry, but should it be something like this?
IEnumerable<string> dirs= Directory.EnumerateDirectories(folderBrowserDialog1.SelectedPath);
GetDirs(dirs);
public void GetDirs(IEnumerable<string> dirs)
{
foreach (var dir in dirs)
{
IEnumerable<string> subdir = Directory.EnumerateDirectories(dir);
if (subdir.Any())
{
GetDirs(subdir);
}
}
}
Some questions
How come the folderbrowserdialog can access the all the systemvolumes with folders and files directly?
In my application I want the user to select folders in the treeview (I want these path to the user selected folders), can I do that in some other way? Maybe should start a new thread for that !
|
|
|
|
|
That looks better, yes.
Anders Hedén wrote: How come the folderbrowserdialog can access the all the systemvolumes with folders and files directly?
It can't do that. Controls and applications either show the top-level, and then you can expand (while waiting); or they show "everything" but then they stop as soon as the visible part is filled, and then you can see more (scroll) while waiting (that is often called "virtual mode").
Experiment: insert a USB stick holding hundreds of files/folders, look at it with some tool; remove it and try to expand/scroll some more, it will fail as the device isn't available to gather more data. (BTW: some apps would close when you remove the stick, Windows Explorer does that).
|
|
|
|
|
Are you trying to load the entire file system into the treeview at application startup? If this is the case, then definitely performance would suffer. Instead, use the TreeView control's BeforeExpand event to populate only the directory the user is trying to expand.
|
|
|
|
|
Yes that is how i do it atm. I know its not the best way. I've tried with the approach with populating the treeview with nodes BeforeExpand , but i haven't found any good option to add "nodedummies" to allow the node to be expanded. An option that doesn't use GetDirectories() to count the underlying subdirectories to add dummy or not.
I could add a dummy to every node and when the user tries to expand the last directory with no underlying directories, the dummy is removed and the expand +-sign for that node/directory is removed. But this is not really nice for the user i think. I cant think of a better way to add dummies, and would gladly receive any tips you have .
|
|
|
|
|
Add the dummy node only if there are subfolders in the directory.
Another option would be to show only the first n sub-directories (where n could be something like 50 or 100 based on your preference) and add a dummy node below them called 'Show more folder'. Expanding that node removes it and adds the next n sub-directories and so on.
modified 20-Jan-12 14:36pm.
|
|
|
|
|
Querying the file system, particularly if networks or non-fixed drives are involved, is a slow operation. I'm not sure .Net is really responsible for this. You might need to design your application in such a way that this can be loaded while the user is doing other things so when it is needed it can be loaded from cache.
|
|
|
|
|
What technology are you using for your UI? If you are using WPF, I would suggest that you can improve your performance quite a bit by turning on UI virtualization, and display only those items that are visible. As Luc suggests, the EnumerateDirectory method is a much better bet for speed, but displaying that much data (a lot of which the user isn't going to see initially) is a time consuming process.
|
|
|
|
|
Hi All,
I am using the following function to copy RAW RGB byte array to Bitmap object. The problem I am facing is when I copy the byte array content through SetPixel method, Image construction is OK and color are proper on the Bitmap. But when I try to use the following function it some how swaps the Red and Blue bytes in the Bitmap causing wrong colors on the Image.
static int WriteBitmapFile(string filename, int width, int height, byte[] imageData)
{
using (Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb))
{
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0,bmp.Width,bmp.Height),ImageLockMode.WriteOnly,bmp.PixelFormat);
Marshal.Copy(imageData, 0, bmpData.Scan0, imageData.Length);
bmp.UnlockBits(bmpData);
bmp.Save(filename);
}
return 1;
}
It seems though when I am copying the byte array in one go it swaps the Red and Blue bytes. SetPixel works fine but is too slow.
Any help in this regard is highly appreciated.
Regards,
|
|
|
|
|
Indeed, GetPixel /SetPixel is not the way to perform operations on an entire image. Here are 3 ideas that may help:
1. you could write a little loop that swaps the bytes in the byte array before executing the code shown.
2. you could try a Bitmap constructor that takes an IntPtr to raw data (may get the same result you have now); make sure to read MSDN's remark though.
3. you could apply a ColorMatrix transformation once the bitmap is filled.
|
|
|
|
|
Thanks for the timely reply Luc.
Can you give some pointers/links/example on how to apply ColorMatrix?
Thanks and Regards,
|
|
|
|
|
This is because the pixel format expects the bytes in the other order from what you're providing (BGR, I think. The 4 byte one is BGRA iirc). I would transform the bytes on the way in:
byte[] newImageData = new byte[imageData.Length];
for(int i = 0; i < newImageData.Length; i += 3){
newImageData[i] = imageData[i + 2];
newImageData[i + 1] = imageData[i + 1];
newImageData[i + 2] = imageData[i];
}
Unless the image is really large, that should be negligible in time and memory terms and easier than post-processing the image with a ColorFilter.
|
|
|
|
|
You are saying that bitmap is BGR, but I tried using SetPixel with RGB pattern and it worked fine. Does SetPixel works differently than copying RGB data?
|
|
|
|
|
Yes. SetPixel takes a Color, copying byte data just takes raw bytes in the appropriate format.
|
|
|
|
|
Hi whats the accurate and best method to get the time taken to load a control.?.Any idea ?.(I am writing a performance monitoring UI test.)
With thanxx and regards
|
|
|
|
|
I think to get a good answer to this question you need to tell us exactly what you mean by "load a control."
Are you talking about how long it takes to "fill" a databound object, like a ListView, with thousands of rows from its source ?
Are you talking about how long it takes, from the time an end-user double-clicks on a compiled .NET .exe file to present a Window (WPF, WinForms ?) with many controls ... the contents/settings of which ... all (or some) ... need to be calculated when the application launches, rather than being "static," or read in from Application.Settings or other resources ?
"It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle
|
|
|
|
|
Difficult question. The fact that you are timing the "load" might implicate the "load" itself, making it slower.
Do you need this on the live system or just for dev and/or test environment?
V.
|
|
|
|
|
Use the StopWatch class, call Start() right before and Stop() right after the execution of the code you're interested in.
I don't know what you mean by "load a control"; with all the events going on in a WinForms Form when opening up a new Form, it may well be that your control is touched in the Form's constructor, and several event handlers such as Load and Shown . And that other controls also get handled at around the same time.
You might even have to deal with an extra Control which you handle all at once, using your own run-time code only.
Warning: if lots of data is loaded into the control (such as a DataGridView fed by a database), how you organize the data load will predominate, not the generating and painting of the control itself; unless you have coded a large number of operations on a single control and you've forgotten to make good use of optimizing calls such as Control.SuspendLayout() and the like.
|
|
|
|
|
For a form you can time between the first line of the constructor and when the Load event[^] gets fired.
|
|
|
|
|
hi guys
can i get Collection from object if it is part of it?
code should look something like this
public class SomeCollection : CollectionBase
{
public void Add(SomeClass sc)
{
this.List.Add(sc);
}
}
class SomeClass
{
public bool AmIPartOfCollection
{
get
{
}
}
public SomeCollection MyCollection
{
get
{
}
}
}
void Main()
{
SomeClass temp = new SomeClass();
SomeCollection sc = new SomeCollection();
sc.Add(temp);
}
|
|
|
|
|
Not with a standard collection, no. It's pretty straightforward to write a specialised collection and interface for member objects to do this.
However, in most situations you know roughly where the object must be, so you can use targetCollection.Contains.
|
|
|
|
|
Hanzaplast wrote: public SomeCollection MyCollection
Hanzaplast wrote:
you can't do that in general as an object may be part of more than one collection.
|
|
|
|
|
Damn! Beat me to it...
My 5.
|
|
|
|
|
you could have suggested a
public List<SomeCollection> MyCollections {get;}
|
|
|
|
|
The inference I take from your answer, Luc (the answer seems "intuitively" correct to me), is that you could then iterate MyCollections, and, for each Collection in MyCollection, test for the presence of a specifc object using 'Contains. This solution also seeming to allow for the idea that you could also, then ... in the case of an object being a member of more than one Collection ... return a List of all Collections it was a member in, as well.
However, I do think the OP's code is pretty weird. If you are going to add any type of object to a collection: that would seem to indicate a need to me for a generic (even "dynamic," late-bound ?) solution.
thanks, Bill
"It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle
|
|
|
|
|
hi all..
i am using script task in SSIS.i am new to it.
I have a oracle connection string in the code say:
now i want to access this conection via variable: OraConn. how to do it?
is it like below?
OraConn.ConnectionString = Dts.Variables["OraConn"].Value.ToString();
but its not working can anybdy suggest?
FBG
modified 19-Jan-12 8:56am.
|
|
|
|