本文介绍了textbox2(外部formview控件)将在formview控件内部的textbox1中搜索字符串,如果匹配则比它继续进行,否则显示消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有两个文本框:
textbox1在formview控件中,而textbox2在formview之外

textbox1具有数据库中的值.
当用户在textbox2中写一些东西(字符串)时,首先想到我要检查一下,
该值存在于textbox1 ...中吗?
如果存在的话,只有我才能继续努力...

应该区分大小写(例如:name和Name不同)

其他

它应该向用户显示消息请输入正确的字符串..."

示例:
Textbox1:一组相关的结构化活动或任务,这些活动或任务为特定客户提供特定服务或产品.

Textbox2:服务

如果我输入Textbox2:服务
它应该显示Message ......

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......

推荐答案

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");
            }

        }



如果您使用按钮进行检查,则将执行此操作.

由于OP的注释而更新了代码;



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

Updated code due to the OP''s comment;

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");
            }

        }


private void TextBox2_TextChanged(object sender, EventArgs e)
        {
            if (this.TextBox2.Text == this.TextBox1.Text)
            {
                MessageBox.Show("Message here");
            }
        }


这篇关于textbox2(外部formview控件)将在formview控件内部的textbox1中搜索字符串,如果匹配则比它继续进行,否则显示消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 00:23