im a beginner to c#. i have the following question.
i want to add a validation for user input such as making sure the year of the car is not greater than the current year +2. where can i add this validation user input.
my main.cs code is like this:
using
System;using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace CarTracker
{
public partial class Main : Form{
public Main(){
InitializeComponent();}
private void listingBindingNavigatorSaveItem_Click(object sender, EventArgs e){
this.Validate();this.listingBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.carTrackerDataSet);
}
private void Form1_Load(object sender, EventArgs e){
// TODO: This line of code loads data into the 'carTrackerDataSet.CarType' table. You can move, or remove it, as needed.this.carTypeTableAdapter.Fill(this.carTrackerDataSet.CarType);
// TODO: This line of code loads data into the 'carTrackerDataSet.Make' table. You can move, or remove it, as needed.
this.makeTableAdapter.Fill(this.carTrackerDataSet.Make);
// TODO: This line of code loads data into the 'carTrackerDataSet.Color' table. You can move, or remove it, as needed.
this.colorTableAdapter.Fill(this.carTrackerDataSet.Color);
// TODO: This line of code loads data into the 'carTrackerDataSet.Listing' table. You can move, or remove it, as needed.
this.listingTableAdapter.Fill(this.carTrackerDataSet.Listing);
}
private void fillByColorNameToolStripButton_Click(object sender, EventArgs e){
try{
this.listingTableAdapter.FillByColorName(this.carTrackerDataSet.Listing, colornameToolStripTextBox.Text);}
catch (System.Exception ex){
System.Windows.Forms.MessageBox.Show(ex.Message);}
}
private void fillByCarTypeNameToolStripButton_Click(object sender, EventArgs e){
try{
this.listingTableAdapter.FillByCarTypeName(this.carTrackerDataSet.Listing, cartypenameToolStripTextBox.Text);}
catch (System.Exception ex){
System.Windows.Forms.MessageBox.Show(ex.Message);}
}
private void fillByMakeNameToolStripButton_Click(object sender, EventArgs e){
try{
this.listingTableAdapter.FillByMakeName(this.carTrackerDataSet.Listing, makenameToolStripTextBox.Text);}
catch (System.Exception ex){
System.Windows.Forms.MessageBox.Show(ex.Message);}
}
}
}
NickPosted Aug 1, 2008, 5:00 AM
If you are trying to provide client side validation, add the condition in the textbox_change event
karabela steelPosted Jul 29, 2008, 5:18 PM
i think i have to add it in the event of my (yearTextBox) validating. the system will add the following code in my main.cs from above.
private void yearTextBox_Validating(object sender, CancelEventArgs e){
}
im stuck here. am i on the right place? how should the code look like. see my question on top.