Solved

Windows App C#

Posted on 2004-03-26
12
378 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
Comment Utility
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
Comment Utility

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
Comment Utility

Also can you tell me how to clear the controls (txt) in the Tab Control?
0
 

Author Comment

by:karra
Comment Utility

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
Comment Utility
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
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 10

Expert Comment

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

Author Comment

by:karra
Comment Utility
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
Comment Utility
Where *exactly* in the SetDefault method did it fail?
0
 

Author Comment

by:karra
Comment Utility
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
Comment Utility
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
Comment Utility
or,

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

For that matter!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now