|
An alternative way (that I just thought of while reading this) might be to trap the form's KeyDown event and then use ActiveControl to check if your SQL Command TextBox is active at the time.
This would, IMHO, be the worst of the several designs I've just suggested. The first button would still appear to be the AcceptButton - VERY confusing.
I'm just mentioning this for complicity.
Paul
|
|
|
|
|
i want to show a string in vs.net debug output window.
i think i can use Trace or Debug class. but i dont now how to use them to display a string in managed code ?
if there exist some other way plz tell?
i want to see the execution and flow of my program
can any bode tell?
plz write the complete syntex.i will be very thank full to u.
r00d0034@yahoo.com
|
|
|
|
|
Debug.WriteLine(string text);
or
Trace.WriteLine(string text);
or
Console.WriteLine(string text);
Give them a chance! Do it for the kittens, dear God, the kittens!
As seen on MS File Transfer: Please enter an integer between 1 and 2.
|
|
|
|
|
I am trying to open an Excel workbook to use in my C# application. I have found many examples of opening a blank (new) workbook using new Excel.Application(). How do I open a specific xls file using Excel.Application ?
//open Excel with new workbook
Excel.Application excel = new Excel.Application();
excel.Application.Workbooks.Add(true);
excel.Application.Visible = true;
I have been able to open a specific file using Process
string path = "C:\\";
string file = "flow.xls";
System.Diagnostics.Process xlProcess = new System.Diagnostics.Process();
xlProcess.EnableRaisingEvents = false;
xlProcess.StartInfo.FileName = "excel";
xlProcess.StartInfo.Arguments = path + file;
xlProcess.Start();
as long as the path has no spaces.
But with a path like
string path = "C:\\Documents and Settings\\userName\\My Documents\\data\\FlowData\\flow.xls";
I also tried a verbatim string
string path = @"C:\Documents and Settings\userName\My Documents\data\FlowData\flow.xls";
How do I add the spaces to the path?
When you come to a fork in the road, take it! Y. Berra
|
|
|
|
|
Excel.Application excel = new Excel.ApplicationClass();
excel.Visible = true;
Excel._Workbook wbk2 = excel.Workbooks.Open(@"c:\mydoc.xls",true,true,true,true,true,true,true,true,true,true,true,true);
if you start putting in too manay features, it no longer remains useful for beginners
quote in a CP article comment, shiraz baig
|
|
|
|
|
Great
Thanks
When you come to a fork in the road, take it! Y. Berra
|
|
|
|
|
Hi,
I am looking for a way to activate an event procedure, such as combox_clicked, without really clicking on the control . I remember in VB we can do thing like that (combox_clicked = true). Just wonder can we do this in C#? I appreciate your inputs.
|
|
|
|
|
Hi
You just need to call the event handler
Like:
First derive from Button, then add the following:
public void CallButtonClick()
{
base.OnClick(this, EventArgs.Empty);
}
Now , call the function from your code
Hope this helps, there seems to be many ways to do this though.
Give them a chance! Do it for the kittens, dear God, the kittens!
|
|
|
|
|
Hi Leppie,
I am not sure if I understand what you mean by
leppie wrote:
First derive from Button, then add the following:
public void CallButtonclick()
{
base.onclick(this, EventArgs.Empty);
}
Can you please give more detailed explaination? I really appreciate that!!;)
|
|
|
|
|
D Shen wrote:
I am not sure if I understand what you mean by
It's the beauty of inheritance
OK. Lets see how/why I say that
1. What we want is a button that we can programatically fire events. It makes sense to add this functionality to the Button class. So we make one:
public class ButtonEx():System.Windows.Forms.Button
{
public void CallButtonclick()
{
base.OnClick(EventArgs.Empty);
}
}
2. We replace our existing Button in the in the form with our new ButtonEx.
private System.Windows.Forms.Button button1;
private ButtonEx button1;
And in the windows forms designer region, change :
button1 = new System.Windows.Forms.Button();
button1 = new ButtonEx();
Be sure to save before viewing in the designer(in fact close it beforehand, it does more harm than good ).
3. Finally we just call our new ButtonEx's CallButtonClick methods as follows:
button1.CallButtonClick();
NOTE: If you'll be calling this method from thread u will need to invoke it. I'm not 100% sure, but it would look something like this:
button1.Invoke( new MethodInvoker(button1.CallButtonClick));
Hope this adds some insight
Give them a chance! Do it for the kittens, dear God, the kittens!
|
|
|
|
|
Thank you, leppie. It really helps!
|
|
|
|
|
leppie,
Here comes a minor problem
When I compile the code, I got "...does not contain a definition for..." this button1.
I followed the order you post here, but.... Please help!!
|
|
|
|
|
leppie,
I found the problem, it was so stupid.....(typo )
|
|
|
|
|
Hehe, thought it was either that or the designer screw'd up the UI
Give them a chance! Do it for the kittens, dear God, the kittens!
As seen on MS File Transfer: Please enter an integer between 1 and 2.
|
|
|
|
|
Sorry, I'm a bit DOPEY
I didnt see that it was a combobox you were talking about, but the way to do it is the same, just follow the steps
Give them a chance! Do it for the kittens, dear God, the kittens!
|
|
|
|
|
Does anybody know if there is a way to use the GetFiles method to retrive files using more than one search pattern (similar to what you can do with the OpenFileDialog class). For example, I want to use the GetFiles method to return all image files with the *.jpg, *.bmp, *.gif, etc extensions but it seem the method will only take one at a time and won't accept a string in the same format as the the FileDialog class. I thought about making multiple calls to GetFiles and putting the results into a stack and then popping them out one-by-one to sort them together into one array but I wanted to see if anybody could come up with an easier way.
Thanks
|
|
|
|
|
There isn't a very easy way but you could get all the files, regardless of extension and then remove all the ones that don't fit the profile (a quick RegEx will do that neatly).
Paul
|
|
|
|
|
I have this code in my Clear() routine:
ds.Tables[0].Rows.Clear();
grdProducts.Refresh();
ds is an in-memory DataSet, not associated with any database, a simple way to access what's in the DataGrid. grdProducts if of course a DataGrid.
The problem is that most of the times I run this code there's an unhandled NullReferenceException exception ("Object reference not set to an instance of an object").
Looking at the stack trace, it happens when the DataGrid is painting itself (after a WndPaint event). If I omit the grdProducts.Refresh() call in my code, I don't see any of my functions in the stack trace, but adding it makes the function in progress appear several levels down the trace (obvious).
Any ideas??
-- LuisR
──────────────
Luis Alonso Ramos
Chihuahua, Mexico
www.luisalonsoramos.com
"Do not worry about your difficulties in mathematics, I assure you that mine are greater." -- Albert Einstein
|
|
|
|
|
Hi
I cant seem to see the problem...
But I have a suggestion is that as you are trying the clear the rows, clearing the table would have the same effect, so will clearing the Columns. Perhaps a cross reference is causing the null reference exception.
Hope this helps
Give them a chance! Do it for the kittens, dear God, the kittens!
|
|
|
|
|
leppie wrote:
But I have a suggestion is that as you are trying the clear the rows
I'm trying to clear the records that the user added. Any other way to do it??
One time, and only one time, I saw another exception about a negative row number.
-- LuisR
──────────────
Luis Alonso Ramos
Chihuahua, Mexico
www.luisalonsoramos.com
"Do not worry about your difficulties in mathematics, I assure you that mine are greater." -- Albert Einstein
|
|
|
|
|
Hmm, DataTable.Rows.RemoveAt() ??? Very strange indeed!
Give them a chance! Do it for the kittens, dear God, the kittens!
|
|
|
|
|
I added a if(dt.Tables[0].Rows.Count > 0) before clearing all rows, and it seems to work now...
-- LuisR
──────────────
Luis Alonso Ramos
Chihuahua, Mexico
www.luisalonsoramos.com
"Do not worry about your difficulties in mathematics, I assure you that mine are greater." -- Albert Einstein
|
|
|
|
|
I am calling a DLL function from my C# application, but when the application is executed, it takes approximately 5 seconds to complete it.
But if I throw a breakpoint before the call, and step thru it, the function runs in only 1 second?!?
I am letting it run 10 times with and without break points, and it stays consistent.
This is sooo backwards from what I was expecting. Any ideas on why breaking to debug mode speeds up the process!?
See the 3rd message down for a better description of what is happening
|
|
|
|
|
psdavis wrote:
I am calling a DLL function from my C# application, but when the application is executed, it takes approximately 5 seconds to complete it.
Its normal for any .NET language to have a delay at application start.
psdavis wrote:
But if I throw a breakpoint before the call, and step thru it, the function runs in only 1 second?!?
Weird? Can you please supply me some more details, what function are you calling and the implementation?
psdavis wrote:
I am letting it run 10 times with and without break points, and it stays consistent.
More details, you dont state how you loop it? I hope you are not just restarting the application everytime, if so refer to above
psdavis wrote:
This is sooo backwards from what I was expecting. Any ideas on why breaking to debug mode speeds up the process!?
My only debug problems is , that when stopping at a breakpoint and trying to step thru the lines (in rare cases i might add), that the application just freezes.
Give them a chance! Do it for the kittens, dear God, the kittens!
|
|
|
|
|
leppie wrote
Its normal for any .NET language to have a delay at application start.
/nod, but this is in response to a menu item being selected.
leppie wrote
Weird? Can you please supply me some more details, what function are you calling and the implementation?
Unfortunately, it is an outside library that opens up a file in a specific format. I've used this library for a good 5 years though, and it's always run in under a second.
But basically, I'm doing a 'select file', 'open file' when a menu option is selected.
leppie wrote
More details, you dont state how you loop it? I hope you are not just restarting the application everytime, if so refer to above
Nah, just clicking 'File-Open' again with different file names each time. I've run the test around 20 times now, with mix and matches of the files and it's extremely consistent.
|
|
|
|
|