Click here to Skip to main content
15,887,812 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Trying to clear initial content of a group of TextBoxes, the set of codes below, is working:

    y = ActiveControl.Text;
  if (y == "A" || y == "B" || y == "C" || y =="D")
     {
          ActiveControl.Text = string.Empty;
     }

But this other set is not working:

  if (ActiveControl[].Text.Contains("A", "B", "C", "D))
      {
         ActiveControl.Text = string.Empty;
      }

Though I prefer the last set of codes to the 1st one.
Somebody help me out please.
Thanks.
Posted
Comments
[no name] 4-May-14 7:20am    
It's not working because the Contains method only take a single string as a parameter. And ActiveControl[]? What is that? Why can't you iterate over the controls collection?
Salisu Shaibu 4-May-14 8:12am    
@ OriginalGriff:
Thanks Man, its perfect but I actually prefer ActiveControl.Text.Contains(....) method for other uses.
You're really appreciated.
Shaibu.

1 solution

The trouble is that the second version won't compile. You could try this:
C#
private static string[] validList = new string[] { "A", "B", "C", "D" };
...
if (validList.Contains(ActiveControl.Text))
    {
    ...
    }
 
Share this answer
 
Comments
Salisu Shaibu 4-May-14 8:07am    
@ OriginalGriff:
Thanks Man, its perfect but I actually prefer ActiveControl.Text.Contains(....) method for other uses.
You're really appreciated.
Shaibu.

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