Solved

Windows App C#

Posted on 2004-03-26
12
399 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Run time Error 4 47
C#  Radio button search for Date not DateTime 4 46
Device Location 4 29
Cant save 3D 4 19
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
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 Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

815 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

12 Experts available now in Live!

Get 1:1 Help Now