|
Hi Ron,
Each ListViewItem has a Tag property which can be used for storing anything you need. In your case you could associate an ID or a datarow object with it.
Regards,
Serge (Logic Software, Easy Projects .NET site)
|
|
|
|
|
Thanks Serge!
Works great!
Ron
|
|
|
|
|
I created two forms: MainForm has a textbox tbBox1. I clicked a button btnOpen to open the second form (named Form2). Now I want to get or set the value of tbBox1 from the second form by clicking a button btnAccess. How can I do it? The MainForm was opened by the standard "Application.Run(Form MainForm);" and the second form was opened by "Form2 a = new Form2(); a.Show();" in btnAccess's OnClick event. I have made tbBox1 public but I couldn't access the instance of MainForm. The MainForm class' instance (an object) has no name when opened from Application.Run. Please help.
|
|
|
|
|
1. in form2, declare a member System.Windows.Forms.Form pForm;
2. overload the Form2's constructor
public Form2(System.windows.Forms.Form aForm)
{
pForm = aForm;
}
now you can acess Form1 like this.
pForm.xxxButton.Text = "test";
try it.
nhi
|
|
|
|
|
of course,when you create Form2 in form1 ,you should pass itself to the form2's contructor like
Form2 frm = new Form2(this);
frm.Show;
nhi
|
|
|
|
|
Make a function in your second form that takes a Form1 object as a parameter. Then pass "this" as the parameter from the first form
Form2 a = new Form2();
a.myFunction(this);
...
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
Thank you all. I got it work now. I declared the textbox in MainForm as public so that Form2 can get to it. Thanks again.
|
|
|
|
|
Right now I'm writing a wallpaper changing application to run in the systray. The application works great. The app went together really quickly and easily using the .NET framework. However, since it is a systray app.... I want it to be as small as possible in memory.
Just running the app (not even connecting to the web or working with GDI+ for imaging) it sits at about 12M in memory with 5M virtual memory. This is the release version of the code.
Is there anything I can do to reduce the footprint? I liked the speed of development, but I don't know if it is worth almost 20M in memory.
Thanks,
Dave
|
|
|
|
|
Take a look at System.Diagnostics.Process.MaxWorkingSet and MinWorkingSet properties.
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
Thanks, I looked but the min is set to 204,800 and max is set to 1,413,120. I'm not exactly sure what these values are expressed in... bytes, KB,megs, pages, something else?
It doesn't look like they are that large. How do I change the values?
When I try to set the value I get a:
Cannot implicitly convert type 'int' to 'System.IntPtr'.
Thanks again,
Dave
|
|
|
|
|
That's the .NET Framework for you. Depending on what Types you use, the defining assemblies are loaded into memory. This can produce a large footprint, and there's really nothing you can do about it.
As far as setting the MaxWorkingSet , you have to assign it new IntPtr(someIntOrLongValue) , since the property type is an IntPtr . You should read the documentation about the Process.MaxWorkingSet property. You can only set this to a value that still allows all the assemblies to be loaded into memory.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
.NET DataGrid drawing header text according to it's DataGridColumnStyle Alignment.
I want to draw header text at center of column.
also, i want to draw image at header.
I tried to override OnPaint Method. But it is not good way.
Is there any simple way to do that using window message and functions?
i have to finish this job quickly.
Help me!
thanks to regards.
SeungPil Lee
|
|
|
|
|
The Paint method is called to draw your contents, not the header. You can align the header - though it'll align the contents as well - by setting the DataGridColumnStyle.Alignment property to HorizontalAlignment.Center .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I copy the MSDN demo source code and run it. but nothing happens.
Does it need other system settings? or what?
thanks!
NHi
|
|
|
|
|
You mean from the FileSystemWatcher class documentation? Did you specify a directory to watch? The source code is correct.
Instead of just copying and pasting source code, read about the class, understand it, then write a sample of your own. Copying and pasting source code won't teach you anything.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
Instead of just copying and pasting source code, read about the class, understand it, then write a sample of your own. Copying and pasting source code won't teach you anything.
Heath, I voted you a five and thought you might want to include this in your sig. Might save you some keystrokes.
Yes, I program in VB, but only to feed my addiction to a warm place to sleep and food to eat!
Visit my Code Project blog (Mobile Audio project)[^]
|
|
|
|
|
Thanks.
Yeah, I think I understand it correctly. I noticed all the control's attributes and functions. The wathcher control is quite well wrapped and easy to use, I consider. Copy and paste source code in MSDN document is the last step I tried. The following is the sample.
public class Watcher
{
public static void Main()
{
// Create a new FileSystemWatcher and set its properties.
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = "e:";
/* Watch for changes in LastAccess and LastWrite times, and
the renaming of files or directories. */
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
// Only watch text files.
watcher.Filter = "*.txt";
// Add event handlers.
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.Created += new FileSystemEventHandler(OnChanged);
watcher.Deleted += new FileSystemEventHandler(OnChanged);
watcher.Renamed += new RenamedEventHandler(OnRenamed);
// Begin watching.
watcher.EnableRaisingEvents = true;
// Wait for the user to quit the program.
Console.WriteLine("Press \'q\' to quit the sample.");
while(Console.Read()!='q');
}
// Define the event handlers.
private static void OnChanged(object source, FileSystemEventArgs e)
{
// Specify what is done when a file is changed, created, or deleted.
Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType);
}
private static void OnRenamed(object source, RenamedEventArgs e)
{
// Specify what is done when a file is renamed.
Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath);
}
}
fay
|
|
|
|
|
OK, I got the answer now.
The only one point caused it did not work is:
watcher.Path = "e:";
the correct code is
watcher.Path = "e:\\";
other similar code works as well when modify them as above.
the conclusion is: The FileSystemWatcher's Path attribute needs a "\" at the end.
fayth
|
|
|
|
|
I hate to chase all the way the latest technologies, this is why while others are switching their lanes to Java or C#, I'm still a C++ programmer. But now I think it's time for me to change, and I'll have to chose among Java and C# my next generation language.
What's your opinion ? I think maybe this is wrong place to ask, cuz it's C# place...
Horace3801
|
|
|
|
|
why one of them?
why not both of them?
It is a tool by itself. I utilize either of them depending on the project.
nhi
|
|
|
|
|
Are you sure that you'll stick to windows during the next few years?
Yes: C# !
No: Java !
Do you code desktop applications, or web applications?
Desktop: C# !
Web: Java !
If you are not sure about what you will use your new language for, I suggest you learn Java. Switching from Java to C# later on is easy, because C# is not much more than a combination of Java and C++.
|
|
|
|
|
I'd have to say that I disagree with your web application recommendation. I don't think a desktop vs. web argument can be made unless you need to be flexible with the client/server OS.
|
|
|
|
|
If you think Java will be useful in your career you should learn to use it. For an experienced C++ developer Java is relatively simple to learn. It is the API that is large not the language differences.
Should you learn C#? IMHO the correct question is should you learn .NET?
Just as with Java if you think .NET will be useful in your career then Yes. However you don’t need to learn C# (not that it would be difficult… just like Java it is the API that is large not the language ) when you can write .NET code in C++. In fact some would say (including me) that C++ is THE language since you can do "mixed mode" development.
Of course, there are some differences in approach and/or capability across the languages but they are few rather than many. Again the most significantly different one is C++ due to the "mixed mode" capability.
But, that’s just my opinion… I could be wrong.
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
As "EastenChild" said, learn both. Of course, that's only if you have time. I went from C/C++ many years ago to Java, Perl, VB, and then several managed languages back in the .NET 1.0 beta days. Of course, I learned HTML, Javascript, etc. etc., though I started when HTML 1.0 was still a draft.
While you can actually learn these in tandem - since there's many common features such as managed allocation, garbage collection, etc. - that might not be suitable depending on your time. But remember this is really a choice between Java and .NET. .NET is actually Microsoft's brand-name for the Common Language Infrastructure, or CLI. This describes how languages interoperate (through Intermediate Language, or IL), how that IL should be formed, metadata, etc. The CLI specs are easy to find on the web. An assembly writtin in one language can be used by another, since they all compile down to the same thing (roughly, not taking into account compilere optimizations or amount of support for the CLI).
As the poster above said, pick which you think will be most useful to you in the future. Both Java and the C# language are similar to C/C++, and very similar to each other. J# is closer to Java, of course, but typically uses assemblies that more closely match the JRE (Java Runtime Environment). It can use the .NET FCL (Framework Class Libraries, sometimes referred to as the BCL, or Base Class Libraries) just like C#, VB.NET, et. al. can use the JRE-like assemblies.
Personally, I like .NET much more. While Java is further ahead in platform support, it's being screwed to the ground. Sun is refusing to open it and it really hasn't advanced much in recent years (and it's not just me saying this, but the whole Java development community outside of Sun...even within Sun sometimes!). .NET is very feature-rich and gives you language independence, so that if you truly understand the .NET Framework and at least have some idea of a particular language syntax, you can write it in any language you want (which is important since many companies don't get it, and require that you know either VB.NET or C#, though sometimes that because an entire team needs to use a particular language).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I agree with a lot of what's been said. I think it's important to learn both Java and C#, but you can do that pretty easily. The APIs are by far the hardest thing to learn. Even those can be learned as you work with projects, though.
My main concern would be: What projects are/will you be working on? If you know of upcoming C++ projects, then stick with that and start learning the .NET Framework. From there, you can slide into C# - and you'll be productive, too, since you already know the Framework. After that, you can take the larger jump to Java. The language will be easy, but the API might take a while.
Personally, I think that the .NET Framework is laid out better and seems to be more thought-out than Java APIs. And, considering Visual Studio is the undisputed champion of development environments, I believe that this would be a good path. But, again, it all depends on marketability. Base your decision on the projects you are working on and those you will be working on in the near future.
Michael Flanakin
Web Log
|
|
|
|
|