• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 476
  • Last Modified:

Combo Box Selected Value

Hi,

I have a class file where am passing controls from a form in loop

foreach (Control frmControl in frm.Controls)
if (ReferenceEquals(frmgbxcontrol.GetType(), typeof (ComboBox)))

Open in new window


I need to read the selectedvalue of combo box here. What do I do ?
0
GRChandrashekar
Asked:
GRChandrashekar
1 Solution
 
käµfm³d 👽Commented:
Cast. I suggest using the as operator (http://msdn.microsoft.com/en-us/library/cscsdfbt(v=vs.71).aspx) instead.

foreach (Control frmControl in frm.Controls)
{
    ComboBox cb = frmgbxcontrol as ComboBox;

    if (cb != null)
    {
        MessageBox.Show(cb.SelectedValue.ToString());
    }
}

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now