CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2011
    Posts
    54

    setting combo-box to enable/disable in a code...

    I have a form (frmMain) with one panel, 3 buttons and a combo box (this is outside of the panel)..

    is there a way to enable/disable the combo-box when one of the buttons is enabled (say button 1 is enable, i want the combo-box to be enabled too, and if this same box is disabled, the combo box should be disabled too).

    right now i do a loop:

    Code:
    foreach (Control ctrl in this.Controls)
                    {
                        if (ctrl is ComboBox)
                        {
                            ComboBox cb = (ComboBox)ctrl;
    
                            if (cb.Name == "cmbDocumentClasses")
                            {
                                cb.Enabled = false;
    
                                break;
                            }
                        }
                    }
    since I know that there is only one combo box in the form, is there another way to just go directly to this combo-box and set it to Enabled = false?

    Thanks in advance.

  2. #2
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    Re: setting combo-box to enable/disable in a code...

    You should have a member called 'cmbDocumentClasses'. Windows forms puts a member variable named the same as the 'Name' property for each control into the form.

    e.g.

    Code:
    public void Example()
    {
        cmbDocumentClasses.Enabled = false;
    }
    Darwen.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured