|
If it's Windows Forms, then there is a FormClosing event.
private void FormMain_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)
{
}
}
Greetings - Jacek
|
|
|
|
|
Well technically he wanted to know when the X was clicked, which doesn't map directly to FormClosing, since other events could cause the form to close.
If you specifically need to check that the X was clicked, checking the CloseReason on the FormClosingEventArgs might get you closer. Alternatively you can detect the mouse click event instead and figure out where you are. Can't think of a better way off the top of my head.
modified on Wednesday, November 17, 2010 9:27 AM
|
|
|
|
|
Hi All,
I have been searching for a solution for this for some time now but basically I want to copy a table from one SQL Instance to Another using ADO.Net while preserving the schema (including identity and primary key column) - do not want to use SMO
All I have managed to find is how to copy the contents or how to achieve with a single query (which is not possible as they are two different servers) - perhaps my searching skills are failing me on this day
Thanks for any suggestions
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
As I have had no luck with this one then I have decided to use an SQL script file to create the database tables before doing a bulk copy on the data that I need.
The SQL Script file has been created from SQL Management Studio.
I would prefer to do without the need for a script file so if anybody wants to contribute then please do
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
You can create the create table script as a string in C# and execute it over ADO but you still need a script somewhere.
You can also user Select INTO but this does not create the keys and constraints, they need to be scripted.
Your requirements are a little unrealistic not to want to use a script to do something as fundamental as creating an object in the database
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Have you searched the built-in stored procedures?
No guarantees, but I vaguely remember seeing one that does this.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi!
According to the Nested Type Usage Guidelines[^], creating an instance of a nested class by an outside code is generally bad.
I'd like to implement a factory+template+command pattern, in which creating an instance of a command would be forbidden. The factory has instances of all templates. Templates are responsible to validate user's input and, if it's valid, create a Command object. Command class executes itself and has a private constructor. Fortunately, a nested class can access a private constructor of it's parent.
I cannot use a static method, because the factory has to be extensible (it has an AddTemplate(CommandTemplate) method which allows adding new templates).
Here is the code:
class LookCommand : Command
{
public class Template : CommandTemplate
{
private const string NAME = "look";
public override Command TryCreate(RpgOntologyController ontc, CommandParser input)
{
return MatchesCommand(ontc, NAME, input)
? new LookCommand(ontc)
: null;
}
protected string CommandName
{
get { return NAME; }
}
}
private LookCommand(RpgOntologyController controller) : base(controller)
{
}
public override CommandEffect Execute()
{
StringBuilder description = new StringBuilder();
description.AppendLine(new SceneOntologyController(Controller).CurrentSceneDescription);
description.AppendLine();
return new CommandEffect
{
Output = description.ToString()
};
}
void AppendNPC(StringBuilder build)
{
foreach (string npc in new NPCOntologyController(Controller).NearbyNPCs)
{
build.AppendLine(npc);
}
}
}
In the factory:
public Command Create(string input)
{
Command cmd = null;
var commandParser = new CommandParser(input);
if (_templates.Any(template => (cmd = template.TryCreate(_controller, commandParser)) != null))
{
return cmd;
}
throw new ArgumentException("Invalid command.");
}
Can it be an exception of a rule from the Nested Type Usage Guidelines[^]?
Thanks in advance,
Greetings - Jacek
|
|
|
|
|
Yes, it is bad form to instantiate a nested class from outside of its parent. I can't think of a good exception to that rule.
The real question is why does it have to be nested??
|
|
|
|
|
As I have written, it has to be nested because only nested classes have access to a private constructor of another class (in this case is Command ).
Greetings - Jacek
|
|
|
|
|
Hi,
In my application, I use FTP do download single .txt file from multiple devices (up to 100 devices, each with its own IP_adress). At the moment I use single bacground worker, which contains single for loop and goes from first to last device and downloads file to local computer (size of each file up to 5 MB).
Is it better to implement separate backgroudworker for each device, and download files simultaneously and what would be the best approach?
|
|
|
|
|
|
Personally I would stick with downloading one file at a time. You still have to transfer same about of data so it is not like it will be any quicker to download simultaneously
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
This "problem" is basically the same as your earlier one, so I suggest you read this thread[^] again!
|
|
|
|
|
I agree it is similar, but not exactly the same.
For pinging I used for loop with PingIP.DoAsyncPing(IPadress[i]); and it works asynchronous.
I guess I could create backgroundworkers dynamically (for each ftp download) and run them asynchronous.
As I am new to multithreading, I still having trouble differentiating between backgroundworker, thread, thread pool, tasks ...
Basicly I want to create multithread application with different threads (tasks):
1) scan network for devices (if connected)
2) download files using ftp
3) read from files
4) processing file content
5) some actions, based upon proccessed data
|
|
|
|
|
peropata wrote: I used for loop with PingIP.DoAsyncPing(IPadress[i]);
that wasn't my recommendation.
peropata wrote: I could create backgroundworkers dynamically (for each ftp download)
That would be very expensive. Read the other thread again!
peropata wrote: I still having trouble differentiating between backgroundworker, thread, thread pool
They basically are all the same. ThreadPool lends you pre-existing threads (that is cheaper) with very little control. BackgroundWorker is a Thread with some goodies added to it, would probably be OK for your needs.
Warning: BGW needs several properties set true before it starts behaving well!
|
|
|
|
|
So if I understand correctly, it is better to use one background worker (or split between just a few workers).
|
|
|
|
|
hi!!
I have a datagridview in a form. i want to send all the data from the first datagridview to another datagridview, which is present on another form.
Best Regards,
|
|
|
|
|
Which part are you have trouble with? Have you worked out how to communicate with another form yet? (e.g. call a function in another form?)
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
no, actually i couldn't understand how to get data one by one and copy to second DGV.
|
|
|
|
|
Well assuming you have the same columns set up in both tables then you can iterate through the Rows property and add each one. Something like...
foreach(DataGridViewRow row in dgv1.Rows)
{
dgv2.Rows.Add(row);
}
You would obviously need to pass the first DGV's Rows collection to the second form to be processed
Life goes very fast. Tomorrow, today is already yesterday.
modified on Thursday, November 11, 2010 8:58 AM
|
|
|
|
|
when i insert your code the following errors occured.
No row can be added to a DataGridView control that does not have columns. Columns must be added first .
and when i insert column by following code:
foreach (DataGridViewColumn c1 in dataGridView1.Columns)
{
DataGridViewColumn c2 = (DataGridViewColumn)c1.Clone();
dataGridView2.Columns.Add(c2);
}
this error occured:
Row provided already belongs to a DataGridView control.
|
|
|
|
|
OK my mistake, something like this should work...
foreach (DataGridViewRow row in dgv1.Rows)
{
object[] cells = new object[row.Cells.Count];
row.Cells.CopyTo(cells, 0);
dgv2.Rows.Add(cells);
}
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
What is the collection that is used to populate the DGV, datatable, List<>, array[] or is the DGV manually created with no underlying collection.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi,
In my application I need to check and disable a device if it is a USB keyboard or USB mouse. How can i know the type of the device plugged into a system?
Please advice.
Regards,
Joe.
|
|
|
|
|
Maybe you could look into WMI[^] - use google to search for your specific needs
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|