GetType().ToString() unpredictable behavior

Results 1 to 2 of 2

Thread: GetType().ToString() unpredictable behavior

  1. #1
    Join Date
    Dec 1969

    Default GetType().ToString() unpredictable behavior

    I posted this in the MS newsgroups with no reply. Hopefully someone here knows why this is occurring.<BR><BR>I have a large collection of controls within 2 group boxes. My goal is to clear each textbox&#039;s value by looping through all the children of the parent groupbox item. MessageBox.Show-ing the values returned brings back something like this for a textbox and label respectively:<BR><BR>System.Windows.Forms.TextBox< BR>System.Windows.Forms.Label<BR><BR>etc etc for each control.<BR><BR>When I do a string comparison using GetType().ToString(), and setting the text attribute of the control to "", the textbox is cleared, but Label controls are ALSO cleared! This occurs when I do a straight comparison, and when I use CompareTo - both the label and its textbox clear out.<BR><BR>So I hacked out a method that breaks apart the string into an array using the period as a splitter and that works just fine. But this is really a hack at best. Why on earth would the label also be cleared with the textbox when the strings do not compare at all?

  2. #2
    Join Date
    Dec 1969

    Default RE: GetType().ToString() unpredictable behavior

    Somewhat off-topic... But why are you doing this via string compare in the first place? I would think it would be better to do a compare directly on the type and not bother casting it to a string. I have done comparisons very similar to this in the past and had none of the difficulty you are. Post your code?<BR><BR>O&#039;Cary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts