473,394 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

C# - How to raise custom Validation Message in Property Grids?

I am using property grid in C# application. Property grid displays the
propeties properly. But I have some problem in displaying custom validation
message.
I have integer type property. When I give invalid values for the property it
is throwing System exception as follows.

"Invalid Property Value. Is not a valid value for Int32.

Though I have custom validation message in the Property set system throws
exception before this.

Is there any way to override system defined exception?

How can I avoid this?

Can anyone help in this?

Thanks in advance.

Regards
Shanthi
Nov 15 '05 #1
2 9225
I'm not sure as though I understand.

You mean you have a property of your type, say, "prop" that is of type
System.Int32, and so is used like thus -

........
MyObj.prop = 4;
........

and you want to override exceptions you get when you try to set it to
something invalid, like thus -

........
MyObj.prop = "blah";
........

My first assumption would be, no, you can't and shouldn't override the
default exceptions you'd get back. My feelings are that if I could
circumvent the exceptions, somehow, that would get generated by
mis-assignment of types that would be a major flaw in the type-safety of the
..Net runtime itself.

Remember that properties are functions. And what you're trying to do is,
from within the function, catch an invalid parameter value AFTER it has
already been constructed on the stack-frame for that function, type-checked
and so forth. I don't see how this is possible.
"Shanthi" <st*@srasys.co.in> wrote in message
news:OC****************@TK2MSFTNGP09.phx.gbl...
I am using property grid in C# application. Property grid displays the
propeties properly. But I have some problem in displaying custom validation message.
I have integer type property. When I give invalid values for the property it is throwing System exception as follows.

"Invalid Property Value. Is not a valid value for Int32.

Though I have custom validation message in the Property set system throws
exception before this.

Is there any way to override system defined exception?

How can I avoid this?

Can anyone help in this?

Thanks in advance.

Regards
Shanthi

Nov 15 '05 #2
Thanks for the reply.

I agree with you that overriding the system exception may not be a good
idea.
What I need is to validate the inputs to the propety grid.
I am trying to resolve this problem from another angle now.
Is it possible to validate key strokes while the user enters so that I can
disallow chars where the fields need to be numeral. Looking for some key
board / data change events on the property grid.
Thanks & Regards
Shanthi

"Ben Rush" <kw*****@yahoo.com> wrote in message
news:OX**************@TK2MSFTNGP09.phx.gbl...
I'm not sure as though I understand.

You mean you have a property of your type, say, "prop" that is of type
System.Int32, and so is used like thus -

.......
MyObj.prop = 4;
.......

and you want to override exceptions you get when you try to set it to
something invalid, like thus -

.......
MyObj.prop = "blah";
.......

My first assumption would be, no, you can't and shouldn't override the
default exceptions you'd get back. My feelings are that if I could
circumvent the exceptions, somehow, that would get generated by
mis-assignment of types that would be a major flaw in the type-safety of the .Net runtime itself.

Remember that properties are functions. And what you're trying to do is,
from within the function, catch an invalid parameter value AFTER it has
already been constructed on the stack-frame for that function, type-checked and so forth. I don't see how this is possible.
"Shanthi" <st*@srasys.co.in> wrote in message
news:OC****************@TK2MSFTNGP09.phx.gbl...
I am using property grid in C# application. Property grid displays the
propeties properly. But I have some problem in displaying custom validation
message.
I have integer type property. When I give invalid values for the property it
is throwing System exception as follows.

"Invalid Property Value. Is not a valid value for Int32.

Though I have custom validation message in the Property set system

throws exception before this.

Is there any way to override system defined exception?

How can I avoid this?

Can anyone help in this?

Thanks in advance.

Regards
Shanthi


Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Chris Barrow | last post by:
Hi everyone, Does anyone know if it is possible to append your own javascript function onto the end of a button's onclick method when validation controls are used? Here is an example of the...
3
by: simon | last post by:
I have 2 <asp:textbox controls>: <asp:textbox id="txt1" Runat="server" ></asp:textbox> <asp:textbox id="txt2" Runat="server" ></asp:textbox> User must insert the value either in txt1 OR in...
1
by: Stephen Adam | last post by:
Hi there, I have written a custom validation control which checks to see of an input field is not empty and contains only numeric data. I was using a regular expression validation control but...
6
by: jk | last post by:
Looking through WebUIValidation.js, I discovered that the standard validators don't cater for non-numeric date formats (e.g. dd-MMM-yyyy) which I would like to do To keep code to a minimum, I...
5
by: | last post by:
Hi all, Has anyone been able to write some custom javascript on the onclick event of submit button to do certain things like disable submit button, only submit form once etc. This was a breeze...
1
by: Fendi Baba | last post by:
I wrote a simple validation routine. I am trying to trigger validation on group of fields if an option on another radio button is selected. Sub ValidateAdd_ServerValidate(ByVal objSource As...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
1
by: asharda | last post by:
I have a custom property grid. I am using custom property grid as I do not want the error messages that the propertygrid shows when abphabets are entered in interger fields. The custom property...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.