Click here to Skip to main content
15,889,781 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have two textboxes in my application :
textbox1 is in formview control and textbox2 is out side formview

textbox1 has value from database.
when user write something(string) in textbox2 first think I want to check that,
that value exist in textbox1...?
if it exist than only I can procced furthere...

It should be case sensitive(e.g : name and Name are different)

else

it should display Message to user that "Please enter Correct String..."

Example :
Textbox1 : A collection of related, structured activities or tasks that produce a specific service or product for a particular customer.

Textbox2 : service

if I type in Textbox2 : SErvice
It should display Message......
Posted
Updated 23-Mar-11 8:59am
v3
Comments
Orcun Iyigun 23-Mar-11 15:47pm    
so when you search "coll", it will read the collection and find "coll" in it then display a message or you want to search only word by word?
uipatel 24-Mar-11 9:55am    
I want to search word by word
lets say in above example I want to search "produce" OR "Structured activities"
Orcun Iyigun 24-Mar-11 11:29am    
ok check my answer.

C#
private void button3_Click(object sender, EventArgs e)
        {
            string searchWithinThis = textBox4.Text;
            string searchForThis = textBox5.Text;
            int firstCharacter = searchWithinThis.IndexOf(searchForThis);
            if (firstCharacter == -1)
            {
                MessageBox.Show("please enter correct string");
            }
            else
            {
                // do stuff
                MessageBox.Show("OK");
            }

        }


If you are using a button to check, this will do it.

Updated code due to the OP's comment;

C#
private void button3_Click(object sender, EventArgs e)
        {
            string searchWithinThis = textBox1.Text;
            int count = searchWithinThis.Split(' ').Length - 1;
            bool flag = false;
            string[] words = new string[count];
            words= searchWithinThis.Split(' ');
            for (int i = 0; i < words.Length; i++)
            {
                if (textBox2.Text == words[i])
                {
                    flag = true;
                }
            }
            if (flag)
            {
                //do stuff
            }
            else
            {
                MessageBox.Show("correct the string");
            }

        }
 
Share this answer
 
v2
Check the event when you want to validate this.


C#
private void TextBox2_TextChanged(object sender, EventArgs e)
        {
            if (this.TextBox2.Text == this.TextBox1.Text)
            {
                MessageBox.Show("Message here");
            }
        }
 
Share this answer
 
Comments
uipatel 23-Mar-11 14:49pm    
no this is not working....
luisnike19 23-Mar-11 15:35pm    
why>?? did you subscribe the control to the event?
uipatel 24-Mar-11 9:57am    
thank you for reply, ya I subscibe the control not working...
please read my question carefully...
luisnike19 24-Mar-11 15:32pm    
Use events
Orcun Iyigun 23-Mar-11 16:12pm    
Have you check your code?
In order to get to inside of if statement, the value of TextBox2.Text should be identical to the TextBox1.Text?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900