Hi
I am Using the Data Source to create My windows Form
My Form contain Some Textboxs I m using Error provider to validate it
when i m runing my form the textboxs is empty ...
i need to fir my error provider when clicking on the save button that created when using the data source to create this form....need help..Sorry for my bad language :D
Loading

Ahmed SolimanPosted Jun 13, 2008, 7:18 PM
but you have misunderstanding :
this is my Save button code till now:-
private void stockBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.stockBindingSource.EndEdit();
this.stockTableAdapter.Update(this.solyappDataSet.Stock);
}
this my textbox error provider:
private void stock_IDTextBox_Validated_1(object sender, EventArgs e)
{
bool bTest = stock_IDTextBoxIsValid();
if (bTest == true)
{
this.errorProvider1.SetError(stock_IDTextBox, "Please Enter Stock ID in Correct Format(1,2,3...)");
}
else
{
this.errorProvider1.SetError(stock_IDTextBox, "");
}
}
private bool stock_IDTextBoxIsValid()
{
if (stock_IDTextBox.Text == string.Empty)
{
return true;
}
char[] testArr = stock_IDTextBox.Text.ToCharArray();
bool testBool = false;
for (int i = 0; i < testArr.Length; i++)
{
if (!char.IsNumber(testArr[i]))
{
testBool = true;
}
}
return testBool;
}
You Said"If your textbox is empty and someone click on your save button
it should fire the errorProvider and display some messages like "Please fill the textbox"
this is right
I was trying if condtion but it dose not work i think the problem is the way you fireing the Error provider when you using BindingSources to Create The Form.
Thanks again.
A.Soliman
Niradhip ChakrabortyPosted Jun 13, 2008, 1:05 AM
What I understood from your post.If your textbox is empty and someone click on your save button
it should fire the errorProvider and display some messages like "Please fill the textbox".
If this is the case you can do it in more simple way. You can use a messagebox to display the error messsage.
private void btnsave_Click(object sender, System.EventArgs e)
{
if (txtEmployeeID.Text == "")
{
MessageBox.Show("Please provide the EmployeeID!");
}
}
Say your save button ID is btnsave and your textbox ID is txtEmployeeID.
If you really want to use error provider control,You can check the following article:
http://www.c-sharpcorner.com/UploadFile/DipalChoksi/UsingErrorProviderContolinWindowsFormsandCSharp11242005010829AM/UsingErrorProviderContolinWindowsFormsandCSharp.aspx
If my understanding is wrong from your post please let me know.