Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 9th, 2005, 11:12 AM
Authorized User
 
Join Date: Apr 2005
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Range Validator in ADO.net

how can i include range validation in textbox ? using C# with ADO.net?

Abdul Wasie
__________________
Abdul Wasie
 
Old April 9th, 2005, 10:39 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Hi Adbul,

The following will give the user immediate validation feedback when they tab out of an unbound textbox.

1. Create a form with a textbox and a button (the button's only purpose will be to provide a control to receive focus when you tab out of the textbox). Drop an ErrorProvider control on the form to place it in the components tray. Name the ErrorProvider control 'err'.

2. Create a class to store your range criteria as static properties. Here's the code:

Code:
using System;

namespace RangeValidation
{
    public class Globals
    {
        public static int MinRange{get{return 6;}}
        public static int MaxRange{get{return 12;}}

    }
}
3. In the form's InitializeComponent method, find the code that initializes the textbox. Add the following line of code to wire up the Validating event):

Code:
// 
// txtRange
// 
this.txtRange.Validating += new System.ComponentModel.CancelEventHandler(this.RangeValidate);
Notice that the event handler calls the RangeValidate method.

4. Here's the RangeValidate method:

Code:
private void RangeValidate(object sender, CancelEventArgs e)
        {
            Debug.Assert(sender == txtRange, 
                "RangeValidate method called by wrong control");

            try
            {
                int range = int.Parse(txtRange.Text);
                if(range < Globals.MinRange || range > Globals.MaxRange)
                {
                    err.SetError(txtRange, "Range must be between 6 and 12");
                    e.Cancel = true;
                }
            }
            catch
            {
                err.SetError(txtRange, "BUG: Range must be an integer");
                e.Cancel = true;
            }

            if(e.Cancel)
                txtRange.SelectAll();
            else
                err.SetError(txtRange, "");
        }


Include the System.Diagnostics namspace as a using directive.

HTH,

Bob

 
Old April 10th, 2005, 01:27 AM
Authorized User
 
Join Date: Apr 2005
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks bob for replying...

one more problem, i have to open subform from active form so i was hiding the active form and opening the subform when i click on button following is the code which i am using the problem is that when i close my progamme myprogramme.exe is still running in windows task manager - processs

private void button4_Click(object sender, System.EventArgs e)
        {
            this.Hide();
            TCodeCatalog TCode = new TCodeCatalog();
            DialogResult dr = TCode.ShowDialog();

        }

Abdul Wasie
 
Old April 10th, 2005, 07:50 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Hi Abdul,

Not quite sure whats happening there. Processes don't get garbage collected and should terminate when your program returns to the main entry routine:

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
    Application.Run(new Form1());
} //process should terminate here when codepath returns to this point.

The only thing I can think of that might prevent that from happening is if you a spawning a new thread in you code somewhere other than the main UI thread and that second thread isn't terminating successfully.

Bob








Similar Threads
Thread Thread Starter Forum Replies Last Post
Range Validator dcct84 C# 2 October 12th, 2007 08:30 AM
Difference between ADO and ADO.NET rakeshclose2u ADO.NET 2 April 23rd, 2007 03:57 AM
How to create an Excel Range class using vb.net? zayasv General .NET 0 October 30th, 2005 10:21 AM
ADO AND ADO.NET royalsurej ADO.NET 1 November 8th, 2004 08:28 AM
MSDE and SQL CE (using VB.NET and ADO.NET) LEGS ADO.NET 0 July 12th, 2003 11:27 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.