|
If you create a FileStream first using then you can specify what you want to happen to the file.
FileStream fs = new FileStream(path, fileMode);
Where FileMode can be:
FileMode.CreateNew (exception thrown if already exists)
FileMode.Create (overwrites an existing file)
FileMode.Open (exception thrown if does not exist)
FileMode.OpenOrCreate (if exists then opens, otherwise creates)
FileMode.Truncate (opens existing file but wipes it, presumably throws exception if file doesn't exist)
FileMode.Append (appends to existing file)
Once you have opened it you can pass this to the StreamWriter's constructor.
|
|
|
|
|
thanks, that's what I was looking for!
|
|
|
|
|
Hi,
If a user edits a value on a DataGridView, the DataTable under its DataSource recognizes the change when calling DataTable.GetChanges()
However, if I edit a value programatically on the DataGridView, the DataTable.GetChanges() returns a NullReferenceException as if no change took place.
I know it saved to the DataTable, because I can look at it and see the updated value. Is there something else I need to call on the DataGridView after programatically updating it to make the changes noticable on the DataTable? Some type of commit method that is automatically called when a user edits?
Right now I am bypassing the error by updating directly on the DataTable, but I know the DataGridView.Rows is a much smaller collection to loop for changing than the DataTable.Rows (due to filtering already in place). Should I worry about this efficiency issue at all?
Thanks,
Pualee
|
|
|
|
|
The datagridview exists solely for the user's benefit. If you want to programatically modify a data set, modify it in memory - your DataTable directly. That is the correct approach.
|
|
|
|
|
Ok, thanks, I was worried I would never get answered
|
|
|
|
|
Can tell me anybody how can I populate a treeView from a class ... ?
|
|
|
|
|
You populate a TreeView by adding TreeNode s to its Nodes collection. See this[^] MSDN article.
/ravi
|
|
|
|
|
I want to say that I have a class ... with many properties like primitive types or other types created by me.
I have an object populated with dates ... and I want to populate a treeview with dates from this object.
|
|
|
|
|
Can I create a class from a string name??
I want to Make a new instanc class from string name in C#.
for example:
string nameClass = "Class1";
Class1
{
....
}
nameClass newInstance = new nameClass();
Thanks For Your Time.
|
|
|
|
|
|
Yes we can using Reflection.
1. suppose you have added reference of a class 'clsTest' in your project.
2. then add
namespace System.Reflection
using System.Reflection;
now in your code write
Type tpClsTest = Type.GetType("clsTest");
object objTest = Activator.CreateInstance(tpClsTest);
now objTest represents the instance of your clsTest.
sarvesh
C
|
|
|
|
|
Hi.Thanks
Can you Write Example Code For me??
I cant Run that method for my aim.
my aim:
string nameClass = "Class1";
Class1
{
....
}
nameClass newInstance = new nameClass();
how can i write this code with activator??
best regards.
|
|
|
|
|
how can i capture mouse position when my app it's not active?
|
|
|
|
|
Setup a Windows Hook, there are articles on how to do this on this website.
|
|
|
|
|
I am trying to write some some methods which will apply the System.Math methods to arrays instead of individual variables. I thought I might try a generic method (my attempt is below).
public static T[] Abs<T>(T[] array)
{
T[] absArray = array;
for (int i = 0; i < array.GetLength(0); i++)
{
absArray[i] = Math.Abs(absArray[i]);
}
return absArray;
}
The problem comes with the actual call the Math.Abs. The compiler complains:
Error 56 The best overloaded method match for 'System.Math.Abs(sbyte)' has some invalid arguments
Error 57 Argument '1': cannot convert from 'T' to 'sbyte'
Since the compiler doesn't know what type T is, I understand what is happening, but is there a way to make this work (or a better way to do this)?
I was just trying to keep from having to write several identical overloaded methods with differing types (and learn something in the process).
___________________
Brad
|
|
|
|
|
I don't think you can do it this way, T can be anything (int, float, bool, ...). You may have to write a function to get the type of the object and return the object as (int, float, sbyte,... )
|
|
|
|
|
I was afraid that was the answer. If only the System.Math methods were generic...
There isn't any interface that the numeric structs share so that you could specify the array by some interface, either. Oh, well. Lot's of overloads.
Thanks
___________________
Brad
|
|
|
|
|
Hi All
I,m creating an application managing files with custom extension.
I would like that clicking on them the C# application I'm developing starts, read them and execute a task.
I know that the file type should be registered but how to do that in C#?
There is some trick or better way to do it?
regards
Manu Stone
|
|
|
|
|
See this[^] article.
/ravi
|
|
|
|
|
Hi,
I have records with thousands of data which I am binding to DataGridView control. Can I display some data initially and then in background process it fills grid with other data and user do not have to wait for filling all the data and then get control of the form.
Thanks in advance.
Kshitij
|
|
|
|
|
Kshitij Patel wrote: Can I display some data initially and then in background process it
Use, use the DataGridView.VirtualMode property, in it you specify how you want the data to be viewed, like displaying only 10 records, and when the user click on the next button, the next 10 will be loaded, this approach is faster than 1000% in large data records.
|
|
|
|
|
Hi,
I am getting mad. I am building my project with VS.net 2005.
When i build the solution all the button, group box... are display in a "Square" look instead of the normal "Rounded".
Is there an option some where that would allow me to do that.
thanks
|
|
|
|
|
I'm not sure what your talking about, but what I am thinking about as 'square' vs 'rounded' may be the difference in your OS settings on XP to look either like WinXP or like Win2K. These settings are set per user and not by your compiler.
If I'm way off can you describe more?
|
|
|
|
|
Yes This is what i mean by square => win2k and Rounded for XP.
But it's seems that you must be able to build an app that will look like an 2K on a XP PC.
My pc is in XP and all my app build look like a XP app but, that one when i build it it, look like a 2K one.
There must be something on the project that make it build it like that...any idear
|
|
|
|
|
In your Program.cs (or whatever your startup is), you have to enable visual styles. Something like this:
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|