How can I make a textBox value equal to a datagrivew cell value

Dominique1256

I have a winform and 6 textboxes, when I press button1 each textboxes get populated with their corresponding datagridview cell values. When I press button2 after entering a value in textbox6 how can I make a label show the matching value of any of the 5 textboxes. My code below doesn't work. Thank you.

 DataTable dt = new DataTable();
            dt.Load(cmd.ExecuteReader());
            dataGridView1.DataSource = dt;
            textBox1.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();
            textBox2.Text = dataGridView1.CurrentRow.Cells[2].Value.ToString();
            textBox3.Text = dataGridView1.CurrentRow.Cells[3].Value.ToString();
            textBox4.Text = dataGridView1.CurrentRow.Cells[4].Value.ToString();
            textBox5.Text = dataGridView1.CurrentRow.Cells[5].Value.ToString();


private void button2_Click(object sender, EventArgs e)
    {
        if (textBox1.Text.Equals(textBox2.Text))
        {
            label1.Text = "this is equal to textBox1";


        }
joko

You could loop through all textboxes but #6 and compare the text of your textBox6:

foreach (TextBox control in Controls) //all textboxes but textbox6, because you dont want to compare it with itself
            {
                if (control.Text.Equals(textBox6.Text) && textBox6 != control)
                {
                    label1.Text = control.Text;
                }
            }

If you have more textboxes in your form you need to exclude them as well to prevent the loop from comparing them too. You can achive this by putting them in a panel of something similar.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I make my MsgBox Appear if the Equip_No is not equal to the value in the Equip_no Textbox?

From Dev

How can I make my MsgBox Appear if the Equip_No is not equal to the value in the Equip_no Textbox?

From Dev

How can I make the value be equal to localstorage or default to "0"

From Dev

How can i save a value in the textbox to a variable

From Dev

How can i get value from textbox?

From Dev

How can i check a value is pasted in Textbox?

From Dev

How can I make a cell in Excel to change colour according to the value of other cell?

From Dev

How can I get the value of a label in a cell

From Dev

How can I use a textbox value to set a value on a radiobutton

From Dev

I want to check if textbox value is equal to my specific value

From Dev

how to get value of cell in table and display it in textbox

From Dev

Get the value of a textbox to a cell

From Dev

Get the value of a textbox to a cell

From Dev

copy value of cell into textbox

From Dev

How can I make it so that a form's Text property will always equal a textbox's?

From Dev

How can i make a UISlider with step value

From Dev

How can I make a dynamic value for update?

From Dev

How do I make Excel cell contents show a different value

From Dev

How do I make a cell return a value based on the characters.?

From Java

How can I test that a value is "greater than or equal to" in Jasmine?

From Dev

How can I set the value of textbox to "0" if blank or empty?

From Dev

How can I convert textbox value to double in c#?

From Java

How can I sum multiple Numeric textbox value?

From Dev

How can I set the value of textbox to 0 if blank or empty?

From Dev

How can I get textbox value into array and convert into integer in java

From Dev

How can I add value to existing textbox in xaml

From Dev

How can I get button value in textbox of model pop up?

From Dev

How can I overload equal method to make different objects have same hashcode value in unordered_multimap in my case

From Dev

How to get the first cell in range which value is equal to a specific value

Related Related

  1. 1

    How can I make my MsgBox Appear if the Equip_No is not equal to the value in the Equip_no Textbox?

  2. 2

    How can I make my MsgBox Appear if the Equip_No is not equal to the value in the Equip_no Textbox?

  3. 3

    How can I make the value be equal to localstorage or default to "0"

  4. 4

    How can i save a value in the textbox to a variable

  5. 5

    How can i get value from textbox?

  6. 6

    How can i check a value is pasted in Textbox?

  7. 7

    How can I make a cell in Excel to change colour according to the value of other cell?

  8. 8

    How can I get the value of a label in a cell

  9. 9

    How can I use a textbox value to set a value on a radiobutton

  10. 10

    I want to check if textbox value is equal to my specific value

  11. 11

    how to get value of cell in table and display it in textbox

  12. 12

    Get the value of a textbox to a cell

  13. 13

    Get the value of a textbox to a cell

  14. 14

    copy value of cell into textbox

  15. 15

    How can I make it so that a form's Text property will always equal a textbox's?

  16. 16

    How can i make a UISlider with step value

  17. 17

    How can I make a dynamic value for update?

  18. 18

    How do I make Excel cell contents show a different value

  19. 19

    How do I make a cell return a value based on the characters.?

  20. 20

    How can I test that a value is "greater than or equal to" in Jasmine?

  21. 21

    How can I set the value of textbox to "0" if blank or empty?

  22. 22

    How can I convert textbox value to double in c#?

  23. 23

    How can I sum multiple Numeric textbox value?

  24. 24

    How can I set the value of textbox to 0 if blank or empty?

  25. 25

    How can I get textbox value into array and convert into integer in java

  26. 26

    How can I add value to existing textbox in xaml

  27. 27

    How can I get button value in textbox of model pop up?

  28. 28

    How can I overload equal method to make different objects have same hashcode value in unordered_multimap in my case

  29. 29

    How to get the first cell in range which value is equal to a specific value

HotTag

Archive