To use this code, simply drag the errorProvider control onto the form, it appears in the list as a red exclamation mark. Add one textbox and one command button, now use this code in the button click event private void button1_Click(object sender, System.EventArgs e)
{
//CHECK FOR DATA ENTRY
if(textBox1.Text =="")
{
//NO DATA!
errorProvider1.SetError(textBox1,"You need to enter a value");
} else
{
//DATA ENTERED DONT SHOW THE ERROR WITH ""
errorProvider1.SetError(textBox1,"");
}
}
You set the error icon active if the data validation is not meet, in this case its if there is no text in the textbox, to hide the errorprovider again simply just include "" instead of putting text in the seterror. You can set the BlinkStyle
of the provider to NeverBlink
, AlwaysBlink
and BlinkIfDifferentError
.You can set those by the properties view in design time or in code in runtime. You can also change the icon at design time to whichever icon you like.
Data Entry Validation with Error Provider
By Colin Harman MACITP, published on 04 Feb 2004
| Filed in
You might also like...
C# forum discussion
-
USB Drive Activity Logger!
by coque0912 (7 replies)
-
Exporting data from a repeater to an Excel sheet
by TomBlack (28 replies)
-
Calculate Date of Birth from Age
by k.prashanth (7 replies)
-
Windows Service, getting outOf memory exception
by programmerdude2341 (3 replies)
-
How to Make Default Button?
by puspitaonlinebooks (24 replies)
C# podcasts
-
.NET Rocks: Stories from CodeMash!
Published 8 years ago, running time 0h56m
While at CodeMash, Carl and Richard collected some great stories. First up is Evan Huack, who digs into cudafy, a library on codeplex that allows you to run C# code (any IL code actually) on your GPU. The second story is about Jessie Shternshus and her company The Improv Effect. Jessie talks abou.
C# jobs
-
.NET, C#, MVC Senior Software Developer
Frontline Technologies, Inc. in Exton, United States
-
C#, JQuery, KnockoutJs. Nhibernate. Unique 3-6 month opportunity in Kitesurfing/Windsurfing heaven
RWI in Cabarete, Dominican Republic
$12,000-12,000 USD per year (Contract) -
C# / .NET Programmer
Mews Systems in Prague, Czech Republic
-
Experienced C# Developer
Zenco Systems Ltd in Rugby, United Kingdom
Annual Bonus, Annual Salary Review, Perfomance Related Bonus
Comments