|
Lets have a simple try at this.
If you have a series of X/Y co-ordinates which is assocaited with some data, the simplist method is this:
Dictionary<Point,YourData> dictionary = new Dictionary<Point,YourData>();
where Point is in the System.Drawing namespace (you could define your own if its not fit for your purpose - its just the dictionary key)
and YourData is any class or data structure of your choosing containing data assocaited with x/y coords.
There sure are many more efficient ways of storing data, but why not get your functionality working and worry about optimization when it becomes a bottleneck.
|
|
|
|
|
To quote the late, great Mitch Hedberg when describing 2-in-1 shampoo...
2-in-1 is a BS term, because 1 is not big enough to hold 2. That's why 2 was created. If it was 2 in 1, it would be overflowing... the bottle would be all sticky...
To store 2 byte values, 2 bytes are required. To store 2 nibbles (half-bytes), sure you could use 1 byte, but the question begs why?
|
|
|
|
|
Hi,
I am receiving a problem with my code. Actually in my code I have taken a list view. name is Listview1. Setting values and performing sorting every thing fine. But when I am trying to display selected value like bellow.
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
this.label1.Text = listView1.SelectedItems[0].ToString();
}
In first click it showing correct value. When clicking the other It throwing exception "System.ArgumentOutOfRangeException: InvalidArgument=Value of '0' is not valid for 'index'.
Parameter name: index".
How can i solve this problem.
Only my intention is it has to display selected value in list view.
How it is possible please show me the solution If any one knows this problem
Thanks in advance.........
sampath-padamatinti
|
|
|
|
|
You are half way there. You need to add one more line.
The problem is that when you select a new item, the old item becomes de-selected, and so the "SelectedIndexChanged" event is fired when there are no items selected. Then, the item you clicked becomes selected, and the "SelectedIndexChanged" event is fired again.
Try this in your code ...
private void listView1_SelectedIndexChanged(object sender, EventArgs e) {
if (listView1.SelectedItems.Count > 0)
label1.Text = listView1.SelectedItems[0].ToString();
}
|
|
|
|
|
Iam new to webparts. I have a list control in a webzone as my webpart.
Now the web part title comes as untitled.
I can set the webpart title using
WebPartZone1.WebParts(0).Title = "MAIN MENU".
But this will fail if i move my webpart to other webpartzone. How can is set the
title even if i move to other webpart zone
|
|
|
|
|
Good morning.
I just started using Directory.GetFiles and I am wondering why it returns the path including the file name. It is my expectation that it would only return a list of file names as I already know the path.
I have the follwoing code:
internal static void DemoGrouping()
{
string[] files = Directory.GetFiles(@"C:\Documents and Settings\TEMP");
var fileList = from file in files
where file.Length > 1
orderby file.Length
group file by file.Length;
foreach (var group in fileList)
{
Console.WriteLine(group.Key);
foreach (string subgroup in group)
Console.WriteLine(" " + subgroup);
}
}
Without getting into substrings to extract the file name, is there a usage of Directory.GetFiles that accomplishes what I am looking for?
Thank you, WHEELS
|
|
|
|
|
Don't think there is.
Alernatively though, use DirectoryInfo.GetFiles() . This gives you an array of FileInfo , and from that you can just get the file name (.Name property).
Regards,
Rob Philpott.
|
|
|
|
|
This (or something close to it) should get you just the file name.
string fileName = System.IO.Path.GetFileName(path);
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
GetFiles() and the like return the full path, which is useful as you can ask those methods to work hierarchically (SearhOption.AllDirectories), so just a filename would not always be sufficient.
You can extract the filename from a full path using the Path class, you can't do the reverse.
BTW: Using DirectoryInfo to get all of them at once is a costly operation if you only are interested in a few of the results returned.
|
|
|
|
|
Thanks to everyone for the excellent replies.
WHEELS
|
|
|
|
|
Hello;
I am working on a little piece of code that copies files from one location to another. I want to display a progress of the operation in the console. I don't want to use P/Invoke win32.
I use File.Copy() method but it seems it is only possible to get the size before and/or after not during the copy.
For the time being, I use two seprate thread, one for copy and another one that display "=" while the copy thread is alive. This shows a progress but it is not very accurate !
I tried with StopWatch, FileSystemWatcher... Any help on this would be greatly apreciated !
|
|
|
|
|
Why not do the copy yourself in appropriate size chunks (say 4KB), that way you can work out exactly how far through you are?
Regards,
Rob Philpott.
|
|
|
|
|
Thanks for your answer
Do you know how would it look like ? I went through several forums for byte[] or buffers but it is not very clear as I am recent to c#
Thanks anyway !
|
|
|
|
|
Google "c# copy file via streams". There are lots of samples...
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Ok thanks
But in a code like this; I can't seem to see where to set the file names like "@c:\test.txt" for example :
public static void CopyStream(Stream input, Stream output)
{
int bufferSize = 4096;
byte[] buffer = new byte[bufferSize];
while (true)
{
int read = input.Read(buffer, 0, buffer.Length);
if (read <= 0)
{
return;
}
output.Write(buffer, 0, read);
}
|
|
|
|
|
Samarchpa wrote: But in a code like this; I can't seem to see where to set the file names like "@c:\test.txt" for example :
It holds inside Stream object.
I Would use StreamReader And StreamWriter
|
|
|
|
|
File.OpenRead(filename) , for example, yields a Stream as the return value
So you could call
CopyStream(File.OpenRead("C:\\input.txt"), File.OpenWrite(C:\\output.txt"));
|
|
|
|
|
Do we really have to hold your hand through the entire process? Be a programmer for god's sake...
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
John Simmons / outlaw programmer wrote: Do we really have to hold your hand through the entire process? Be a programmer for god's sake...
That is for me the purpose of a forum: get some help !! when you are new to a domain and have been searching on the net for hours, the forum comes to be a good solution. Do you really think I did not use google, msdn or else before requesting some help ?
Thanks for those who took the time to answer. I am now searching how to get the total buffer size on the outstream in a variable. If anyone has an idea...
|
|
|
|
|
Hi,
A modern PC should copy from tens to a few hundreds of MB per second.
Copying files with a buffer size that small (4KB) and/or updating progress information all the time, would probably make it much slower (10 or more times slower).
IMO you should use a buffer size that equals a power of 2, and no less than 64KB; I would prefer 256KB or 1MB.
And it does not make sense to update a progress report more often than a few times per second.
If you need to copy several files, then I wouldn't bother copying them with buffers, I would just use File.Copy(). You can calculate progress by summing all the sizes initially, then advance a "done" value by the size of each file copied. A timer (best a System.Windows.Forms.Timer) would suffice to periodically update the progress report.
|
|
|
|
|
I use axShockwaveFlash COM in the my frmSplash windows form for play flash file. I want to ShowDialog frmSplash in my main form. Its properly work. But I use thread I get error, Cannot create axShockwaveFlash component instance.
In my main form contain following code;
private void button1_Click(object sender, EventArgs e)
{
Control.CheckForIllegalCrossThreadCalls = false;
Thread thread = new Thread(DoSplash);
thread.IsBackground = true;
thread.Start();
}
private void DoSplash()
{
frmSplash sp = new frmSplash();
sp.Show();
}
My frmSplash form just contain axShockwaveFlash component. I dont write any code in this form.
How can I solve my problem, thanks...
|
|
|
|
|
Hi,
I have no experience with flash controls, however Control.CheckForIllegalCrossThreadCalls = false; is a mistake. You may want to read this[^] and reorganize your code.
I trust Google could point you to some articles that do it successfully, maybe even at CodeProject!
|
|
|
|
|
On top of what Luc said, you cannot create forms on background threads and expect them to work. They must be created on the UI thread (startup thread) and well as any controls on those forms. Creating UI components on background threads is unreliable and cannot be trusted to work 100% the time.
|
|
|
|
|
Does anyone know of a CAD library for C# / .NET?
Failing that, is there a basic interface library that handles multiple pages in a similar way to Word?
TIA!
I hope you realise that hamsters are very creative when it comes to revenge. - Elaine
|
|
|
|
|