Solved

Windows App C#

Posted on 2004-03-26
12
406 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

791 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