Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 9th, 2005, 11:12 AM
Authorized User
 
Join Date: Apr 2005
Location: Karachi, , Pakistan.
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
Reply With Quote
  #2 (permalink)  
Old April 9th, 2005, 10:39 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
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

Reply With Quote
  #3 (permalink)  
Old April 10th, 2005, 01:27 AM
Authorized User
 
Join Date: Apr 2005
Location: Karachi, , Pakistan.
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
Reply With Quote
  #4 (permalink)  
Old April 10th, 2005, 07:50 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
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



Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:04 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.