|
First, I am not a C# programmer (although I am trying to learn). I have an intern doing the coding for me on this current project, and he is still trying to put together what they teach in school with the real world.
OK, so here's the problem and question...
A form contains a datagrid (2 columns) and some buttons. We want to prevent a record with either of the fields being null from being written to the database (using MSSql). The table in question is set up with "Allow Nulls" as false. This means that if the user clicks "OK" the message "Column 'Div_Code' does not allow nulls......"
This is fine for me, I know what that means. My users don't. They know the field by the name "Division", and they have no idea what null means.
I would like to do either of the following (and I guess there could be a great deal of discussion about which of the solutions is the most elequent):
1) Either check when leaving the field that it is not null. We tried the columnChanging event, but this doesn't work because the field starts as null, ends as null, and only seems to fire when the value changes; or
2) Intercept the message from the database and substitute our own. I tried using a Try block, but although I traced the execution, I could not see where the message came back.
Anyone have a solution (and if there is a 3rd, 4th or 5th approach, that's good also).
Thanks much...
Alan B
|
|
|
|
|
Try handling the DataGrid.CurrentCellChanged event, which is actually independent of the data source. That way the "bug" (as it seems) where null values in a column doesn't fire the ColumnChanging event doesn't really apply. Another option is to bind to a DataView where AllowDBNull is false . The exception message should be fired immediately when the field looses focus so it would take a pretty stupid user (and, yes, I know they exist in mass quantities) to not realize that the value they just entered (or rather, the lack of a value) is not valid so they need to change it.
You can bind a DataGrid to a DataView just as you can any IList or IListSource implementation.
You're not catching an exception because an exception is not thrown by the DataGrid . If anything, it's handling the exception (or just using good error checking) and just displaying a message on its own. Simply throwing an exception would not result in such a message box (at least, not looking like that).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have an app that is an MDI Parent. You can open up multiple child windows and you even have an option to save them (save their position, size, etc...). When I restore them I have a problem because the Z-Order position of the child windows don't get saved. If you have windows that overlap in a particular way the order of the overlap does not get persisted. Anyone know how to do that ?
|
|
|
|
|
Serialize the order yourself. I'm not sure if the Form.MdiChildren is in any order (and the docs do not say), but assuming that they are (and you can always test it) you can do this. Also, is the Z-order when the MDI child forms are deserialized in reverse of what they should be? If so, then it's because they are saved in the same order in which they are read, so you actually need to reverse such a collection of elements (or however you're saving this information) so they are put back in the right order (since newly created MDI child windows will be on top by default).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello,
I was doing an exercise in Kalani's 70-316 book (Exercise 3.1, page 270) concerning exceptions.
The exercise calls for creating a rich text box and loading rtf's into it. However, there is exception handling code in place to handle times when you try to open or save to a file that is already open. The thing is, it doesnt seem an exception is raised at all.
The code has the load file call in a try block and is set to catch IOExceptions and then display a messagebox, indicating that the file is being used by another process. But, when I run the program I can open the file as many times as I want with many different apps. It never complains about the file being used by another program.
Is it not an exception then to use RichTextBox.LoadFile on an already opened file? (I can also save if the file is open by another app)
Thanx for the help,
-Flack
|
|
|
|
|
The RichTextBox doesn't keep the file open so long as you can see it in the editor. The RTB will open the file, read it, then close it. Same thing when the file is saved. If you have two RTB's loading the file AT THE SAME TIME or if the file is locked open by another application (Notepad, Word, ... will NOT do this!), then the exception will be generated.
You can write a small test app that does this. Just create a small app that will open the file on one button click (you don't have to read it, just Open it), and closes it with another button.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
am working on a project which uses pre-compiled executables (for example, makefile.exe) and I want to know if there is a way I can call this program from a C# command, something like:
Application.External.Run(string path, string args)
Application.External.Run("makefile.exe", "/build \"newfile.exe\"");
It doesn't have to be exactly like this; any way is fine. I just want to find SOME way to call another executable with some command line arguments.
Help would be greatly appreciated,
~ZeldaFreak
|
|
|
|
|
Check out the Process class. (Docs on MSDN[^])
Process.Start("C:\\mypath\myexe.exe", "myargs /moreargs");
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Can any one of you let me know, how can I replace a pattern in an html file using C#?
I have the contents of the html file stored in a string. I just need to replace some of the elements which have a similar pattern?
ex: I have a field {Token = LoanNumber} in the html file.
I just need to replace Loan Number with some text by finding the pattern "{Token=}".
Any suggestions are welcome.
Thanks.
|
|
|
|
|
You can use Regular Expressions to do this. Given the example string you posted, your pattern matching string might look something like this:
String token = "Token";
String pattern = @"\{" + token + @"=[\w]*\}";
This will find "{token=somevalue} ".
Your replacement string will look something like this:
String newValue = @"4321";
String replacement = @"{" + token + @"=" + newvalue + @"}";
So now, in a RegEx Replace operation, the result will be:
I have a field {SomeToken=54342643} in the HTML file.
will become
I have a field {SomeToken=4321} in the HTML file.
Create the RegEx object and execute the replacement with something like this:
RegEx regEx = New RegEx( strPattern, RegexOptions.IgnoreCase );
String resultHTML = regEx.Replace( strSourceHTML, strReplacementString );
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Im writing a PocketPC app. The application works fine with the emulator but when i deploy it to my xda2 when trying to create the dataset i get the following error
An unhandled exception of type 'System.TypeLoadException' occurred in System.Windows.Forms.dll<br />
<br />
Additional information: Could not load type System.Data.DataSet from assembly System.Data, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=B77A5C561934E089.
Anyone have a suggestion of whats wrong and how to fix it?
|
|
|
|
|
I could be wrong here, but it sounds like you developed your app on one version of the .NET Framework and the Pocket PC is running the other? (1.0 and 1.1)...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I believe the problem could be because I just installed the Whidbey release. So maybe VS.NET2003 has compiled my app against CF 2.0 rather than 1.0. How can i change what version of the framework an application uses?
|
|
|
|
|
Well, since your using the beta version, I don't know if this is going to work. Go to your Project Properties and find the Supported Runtimes option. The problem is, I don't know if your going to find this option in a CF Project! If not, you'll have to install the Whidbey Framework on your Pocket PC.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I decided to uninstall the CF on the xda and then reinstall it. But before installing it i decided to give the app a go, and strangely it works fine now, although i removed the cf from the settings->remove programs. Oh well it works now!
|
|
|
|
|
I have a .NET client app and a .NET console server app. Whenever the server throws an error, the exception information is as follows, regardless of the type of exception thrown: "The server encountered an internal error. For more information, turn on customErrors in the server's .config file"
Well, I'm currently not using a .config file for the server. Is there a way to turn on custom errors through code? RemotingConfiguration.CustomErrorsEnabled apparently has no effect, unless I'm using it wrong. Any ideas?
#include "witty_sig.h"
|
|
|
|
|
Not using a Web.config file? Why not? You should. It's just a file named Web.config put into the web application's root directory (not necessarily the web server's root directory) with the following (for your needs):
<configuration>
<system.web>
<customErrors mode="On" />
</system.web>
</configuration> Otherwise, you can handle the HttpApplication.Error event and do whatever you want. Typically you implement this in an IHttpModule implementation, but you'd need a .config file to configure your ASP.NET application to use it! You can also handle this in your Global.asax file (or its code-behind file) as well, but many times it's better to abstract your code by making it modular and/or service-oriented.
Seriously, though, you should use a Web.config file. You can configure runtime settings (not just for ASP.NET, but for all of .NET), security, impersonation, etc. etc.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I'm sorry I should've been more clear. The server application is not a web application. It's a standard .NET console application that talks to clients via .NET Remoting. Web.config applies only to web applications correct?
#include "witty_sig.h"
|
|
|
|
|
Correct, but the error resolution message you're getting is typical of ASP.NET web applications, which is why I assumed you were using ASP.NET. What exactly, then, is returning you such an error?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
An example would be when the client tells the server to perform some task and waits for return. While the server is performing some task, it will throw an exception. The client catches the exception, but doesn't tell me the exception type, message, stack trace, etc. and tells me to enable custom errors on the server if I want more information.
#include "witty_sig.h"
|
|
|
|
|
What I mentioned before is close, but now that I understand your client/server app a little better, I can tell you that you need to configure pretty much the same thing, except instead of using <system.web> use <system.runtime.remoting> and set the mode attribute to "on" (lower-case "o", for some reason - not very consistent).
This .config file would be named the same as your client application + .config at the end. The RemotingConfiguration.CustomErrorsEnabled method is merely a way to determine if custom errors are displayed based on the locality of the remote call.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thank you Heath I'll give that a whirl.
#include "witty_sig.h"
|
|
|
|
|
Did this actually work? Could you post an example or emial it to me. I am having the same problem and I am not having any success getting it to work. Currently, I am also not using a config file.
C LaMorticella
Client Instant Access
|
|
|
|
|
I have a form that is being maximized. The form is a child form of an MDI parent and there is another child form docked on the left as a menu. Therefore, when the form is maximized it needs to be maximized to (for instance location 256, 0, 200, 200 instead of 0,0,456,200 (where above is x, y, width, height). I'm having a real issue finding an event that fires BEFORE a maximize command to set the bounds and the maximizedbounds property doesn't seem to be doing any good. Any ideas, events, etc.?
Brian
"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." - Douglas Adams
|
|
|
|
|
Override WndProc and handle the WM_SIZING (0x0214) message. This is sent to a window procedure (and keep in mind that almost all Windows Forms controls encapsulate native controls and dialogs) before being resized. The Message.WParam specifies the edge that is being resized and the Message.LParam specifies the RECT (which you must define in managed code - a System.Drawing.Rectangle will not suffice because it stores coordinates differently).
Set the Message.Result to new IntPtr(1) to signal that you've processed it and don't want your Form to be resized.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|