C#C
C#3y ago
Nikolaaa

❔ problems with foreach loop

            if (buttonTextBoxMap.TryGetValue(currentButton, out TextBox currentTextbox))
            {


                string currentText = new string(currentTextbox.Text.OrderBy(c => c).ToArray());

                foreach (TextBox textBox in textBoxes)
                {
                    if (textBox != currentTextbox) // Provjerite da li je trenutni TextBox isti kao currentTextbox
                    {
                        string textBoxText = new string(textBox.Text.OrderBy(c => c).ToArray());

                        if (textBoxText == currentText)
                        {
                            currentTextbox.Background = new SolidColorBrush(Color.FromArgb(76, 255, 0, 0));
                        }/*
                        else if (textBoxText != currentText)
                        {
                            currentTextbox.Background = new SolidColorBrush(Color.FromArgb(76, 0, 0, 0));
                        }*/ //<----------- THE PROBLEM IS THIS ELSE IF
                    }
                }
            }
hello guys, I have a problem with getting the color of my textbox back because if I put it in a foreach loop some textbox in textBoxes list is not gonna have the same name and it activates the else if. I want it to only activate if none of the textboxes in the list have the same name as currentTextbox. I comented the line where the problem is. It will be red and instantly turn back to black (you can not see it but I debugged it, it does turn to red) because some textboxes have the same name and some don't, how do I make it only if all textboxes do not have the same name as currentTextbox
Was this page helpful?