Solved

Windows App C#

Posted on 2004-03-26
12
411 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
  • 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

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 50 total points
ID: 10691775
or,

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

For that matter!
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How do I bind a WPF ComboBox to an ItemSource using XAML? 2 32
How to read text with RegEx... 2 36
Problem to Office 1 45
Set custom font WPF 2 22
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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

730 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