?
Solved

Windows App C#

Posted on 2004-03-26
12
Medium Priority
?
418 Views
Last Modified: 2008-02-01
I have inherited a form and i have a couple of labels and text of a button to be changed. Is their any way that i can do it?

ALso, I have errorprovider on my form for validating textboxs(abt 10 of them). I have a clear button and i wanted it to clear all the Blinking error Icons when i hit the button. I am ablew to clear all the text but not the blinking error Icon.
0
Comment
Question by:karra
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
12 Comments
 
LVL 10

Expert Comment

by:eternal_21
ID: 10688173
To answer the first question - set the Modifiers property on the button in your parent (base) form to at least Protected (protected, internal, protected internal, public, will all work).  Then you can change it's text in your child (inheriting) form.

How are you clearing the errors now?  Clearing the text should get rid of the blinking icon.  Can you post some code?
0
 

Author Comment

by:karra
ID: 10688237

Thx to Andre, but this is how i am clearing the form right now.

                                private void btnClear_Click(object sender, System.EventArgs e)
            {
                  BackupTexts(this);
                  SetControlsToDefault(this);
            }

            private void SetControlsToDefault(Control control)
            {
                  SetDefault(control);
                  foreach(Control subcontrol in control.Controls)
                  {
                        SetControlsToDefault(subcontrol);
                  }
            }

            private void SetDefault(Control control)
            {
                  //store the textvalues of your textboxes etc in the Tag at designtime
                  control.Text = (control.Tag == null)? null : control.Tag.ToString();
                  if(control is CheckBox)
                  {
                        ((CheckBox)control).Checked = false;
                  }
                  if(control is TextBox)
                  {
                        ((TextBox)control).Text = "";
                  }
                  if(control is ComboBox)
                  {
                        ((ComboBox)control).SelectedIndex = 0;
                  }
            }

            private void BackupTexts(Control control)
            {
                  Backup(control);
                  foreach(Control subcontrol in control.Controls)
                  {
                        BackupTexts(subcontrol);
                  }
            }

            private void Backup(Control control)
            {
                  control.Tag = (control.Text == null)? null : control.Text;    
            }
0
 

Author Comment

by:karra
ID: 10688294

Also can you tell me how to clear the controls (txt) in the Tab Control?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:karra
ID: 10688315

Just for your info (for the above problem):
------------------------------------------------

I am using Validating events for each of the textbox, Which is  bringing multiple error icons for each of the textboxes. (which i wanted to clear).

thx.
0
 
LVL 10

Expert Comment

by:eternal_21
ID: 10688814
How about this to clear the errors?

  void ClearErrors(Control control, ErrorProvider errorProvider)
  {
    errorProvider.SetError(control, String.Empty);
    foreach(Control subControl in control.Controls)
      ClearErrors(subControl, errorProvider);
  }

When you call SetControlsToDefault(this), it should take care of any Tab controls.  Where are you having a problem?
0
 

Author Comment

by:karra
ID: 10688977
It gives me an exception stating that:

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in system.windows.forms.dll

Additional information: Specified argument was out of the range of valid values.
0
 
LVL 10

Expert Comment

by:eternal_21
ID: 10689017
what does the line of code where it fails look like?  Can you post more code?
0
 

Author Comment

by:karra
ID: 10689465
It failed at the SetDefault() method in the above code.

This is what is located in the Debug Window:

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in system.windows.forms.dll

Additional information: Specified argument was out of the range of valid values.

0
 
LVL 10

Expert Comment

by:eternal_21
ID: 10690605
Where *exactly* in the SetDefault method did it fail?
0
 

Author Comment

by:karra
ID: 10691138
Sorry!!!

It failed in the last line. In my guess is it the combo box

private void SetDefault(Control control)
          {
               //store the textvalues of your textboxes etc in the Tag at designtime
               control.Text = (control.Tag == null)? null : control.Tag.ToString();
               if(control is CheckBox)
               {
                    ((CheckBox)control).Checked = false;
               }
               if(control is TextBox)
               {
                    ((TextBox)control).Text = "";
               }
               if(control is ComboBox)
               {
------>>        ((ComboBox)control).SelectedIndex = 0;
               }
          }

System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: '0' is not a valid value for 'index'.
   at System.Windows.Forms.ComboBox.set_SelectedIndex(Int32 value)
   at SO.Generic.SetDefault(Control control)
   at SO.Generic.SetControlsToDefault(Control control)
0
 
LVL 10

Expert Comment

by:eternal_21
ID: 10691757
Instead of,

  ((ComboBox)control).SelectedIndex = 0;

try,

  if(((ComboBox)control).Items.Count>0)
    ((ComboBox)control).SelectedItem = ((ComboBox)control).Items[0];
0
 
LVL 10

Accepted Solution

by:
eternal_21 earned 150 total points
ID: 10691775
or,

  if(((ComboBox)control).Items.Count>0)
    ((ComboBox)control).SelectedIndex = 0;

For that matter!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question