|
I assure you, that Top Level Exception handling is good practise for user facing applications, it is really bad to allow the user to see a raw .net exception. At best it will give the user a load of technical detail that will get them annoyed as they won't understand it, poor dears, this will also make them think the problem is worse than it is when compared to a friendly "Something has gone wrong" popup. At worst I've seen the unhandle exception expose sensitive informtaion such as a connection string with password. Another benefit of Top-Level handlers, is logging for unexpected exceptions across the whole app, this allows the dev team to add new try/catch blocks for specific exceptions that were missed before release. This strategy quickly helps build robust systems.
What is bad practise is to locally provide a "catch all", you should try to catch only specific exception types locally.
|
|
|
|
|
|
There are two courses in one DataGridView, the name and status, the names of those who have the situation I want to show the messagebox. How do I do this?
image : http://www.imageupload.org/?d=302251731[^]
|
|
|
|
|
This got voted down, presumably for the English; however I do not think that fair so I have added a five.
If I understand your question correctly you want to check each row in the grid that contains a keyword ('var' or 'yok'), and take some action based on that word. You will need to iterate through the rows of the grid and check the value in the second column for a match. I expect you need to start with the Rows[^] collection, and proceed from there.
The best things in life are not things.
|
|
|
|
|
Hi, I have 20 TextBoxes in a form. And I have a Common KeyPress Event for all of that Textboxes.
So I try to declare the keypress event like the following manner... is it possible?
for (int Cnl = 1; Cnl < 21; Cnl++)
{
((RichTextBox)Cnl).KeyPress += new KeyPressEventHandler(this.Comn_KeyPress);
}
Thanks for the Ideas..
PARAMU
|
|
|
|
|
try something like this in your Form_Load etc:
foreach (Control ctrl in this.Controls)
{
if (ctrl is RichTextBox)
{
ctrl.KeyPress +=new KeyPressEventHandler(textChanged);
}
}
private void textChanged(object sender, KeyPressEventArgs e)
{
MessageBox.Show(string.Format("You Pressed {0}", e.KeyChar));
}
This will add the key press event handler to all RichTextBoxes on the form.
Hope this helps
...and I have extensive experience writing computer code, including OIC, BTW, BRB, IMHO, LMAO, ROFL, TTYL.....
|
|
|
|
|
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
foreach (Control control in this.Controls)
{
TextBox textBox = control as TextBox;
if (textBox != null) textBox.KeyPress += new KeyPressEventHandler(textBox_KeyPress);
}
}
void textBox_KeyPress(object sender, KeyPressEventArgs e)
{
TextBox textBox = sender as TextBox;
}
}
"You get that on the big jobs."
|
|
|
|
|
|
|
anyone can help me to know that how to generate fix header report with SSRS?
tbhattacharjee
|
|
|
|
|
Hello,
I get
GetAgencyListCompleted EventHandler and
GetAgencyListCompletedEventArg EventArguments delegations from a WebService to check the EventHandler result. The result property (object) of the eventhandler will bring the list of items that what I am looking for.
However, I get implicitly conversion error message in the code below. How can solve the problem?. If you know the solution, would you please show me how to do it?
Thanks.
ProntoWS.GetAgencyListCompleted += new EventHandler <PSSaleWS.GetAgencyListCompletedEventArgs>(Proxy_AgencyInfoCompleted);
void Proxy_AgencyInfoCompleted(object sender, PSSaleWS.GetAgencyListCompletedEventArgs Completed)
{
Response.Write("Here");
}
What a curious mind needs to discover knowledge is noting else than a pin-hole.
modified on Sunday, May 22, 2011 6:26 PM
|
|
|
|
|
The important piece of information missing is the actual type of the GetAgencyListCompleted event but your error message suggests that it is not an
EventHandler <PSSaleWS.GetAgencyListCompletedEventArgs>
If it is typed non generically as
public delegate void GetAgencyListCompletedEventHandler(object sender, PSSaleWS.GetAgencyListCompletedEventArgs Completed);
then the solution is to explicitly create a delegate of the correct type or let the compiler do it for you automatically.
either
ProntoWS.GetAgencyListCompleted += new GetAgencyListCompletedEventHandler(Proxy_AgencyInfoCompleted);
or
ProntoWS.GetAgencyListCompleted += Proxy_AgencyInfoCompleted;
If this doesn't solve your issue then please supply more information about the actual types involved.
Alan.
|
|
|
|
|
Hi Alan!
Thank you for your answer, I got rid of the implicit conversion problem with your approach but Proxy_AgencyInfoCompleted never fires up even I invoke the procedure after ProntoWS.GetAgencyListCompleted += new GetAgencyListCompletedEventHandler(Proxy_AgencyInfoCompleted); statement. Web service doesn't have specific asyncronous methods. Therefore I tried to call the method as follows bur Proxy_AgencyInfoCompleted didn't fire up. Do you have any idea where is the problem? Thank you very much.
ProntoWS.GetAgencyListCompleted += new GetAgencyListCompletedEventHandler(Proxy_AgencyInfoCompleted);
GetAgencyList = GetAgencyList = ProntoWS.GetAgencyList(Agent, User, Password, GetCityName, "TR");
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
Hello everyone,
I'm making a program that works on some lenovo laptops only, it makes use of Sensor.dll. I've used code below:
[DllImport("sensor.dll")]
private static extern void ShockproofGetAccelerometerData(ref APSReading accData);
I'm not sure how should I check if it exits on the system or not. I'm using lenovo laptop therefore program works fine on my system but If someone runs on different system then it should show a message "system doesn't support" or some other error message. Is it possible to check if certain dll is present in system before importing it??
Thank you
Shivam Kalra
|
|
|
|
|
Hi,
the easiest way is by putting your DLL calls (or at least the first one you are going to do) in a try block. The actual lookup of the DLL is postponed till it is actually called, and any error locating it, or its functions, is clearly turned into an exception.
You can find more about it under "Typical Exceptions" in my article here[^].
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
You'll need to dynamically load the DLL at runtime so you can catch if it's not there.
Searching on "c# dynamically load unmanaged dll" yields examples, like this one...
Dynamically calling an unmanaged dll from .NET (C#)[^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thank you guys.
I also found another way of doing it using Files.Exists method of .net.
|
|
|
|
|
That still lets you use DllImportAttribute??
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
In my experience DllImport is not interested in the DLL at all (it is up to the programmer to make sure there eventually will be a DLL file and a function that matches with his prototype).
A C# app builds just fine without the DLL being present; and the calling code throws a DllNotFoundException at run-time whenever it doesn't find the DLL.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Good to know! Thanks Luc.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
You're welcome.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
|
Cool thank you!
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
Iam using VS2010. I have 10 TextBoxes..
In TextBox1 I handled the event for GotFocus,LostFocus...like the following manner...
this.richTextBox1.GotFocus += new System.EventHandler(this.RichTextBox1_GotFocus);
this.richTextBox1.LostFocus += new System.EventHandler(this.RichTextBox1_LostFocus);
private void TextBox1_GotFocus(object sender, System.EventArgs e)
{
TextBox1.BackColor = Color.White;
}
private void TextBox1_LostFocus(object sender, System.EventArgs e)
{
TextBox1.BackColor = Color.LightSteelBlue;
} Like above I need to do all my Textboxes and I need to do the above codings, instead is it possible to have a common GotFocus,LostFocus to all Textboxes to do the above things?
Any Ideas?
Thanks & Regards
PARAMU
|
|
|
|
|
Sure, just wire the following handler to several textboxes:
private void tb_GotFocus(object sender, System.EventArgs e) {
TextBox tb=sender as TextBox;
if (tb!=null) tb.BackColor = Color.White;
}
You can do the wiring up at run-time, or using Visual Designer (click the event, choose an existing handler, after you added the above code, that is).
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|