if (ctrl is TextBox) { string MyText = ((TextBox)ctrl).Text; } else if (ctrl is ComboBox) { int MyValue = ((ComboBox)ctrl).SelectedValue; } // etc.etc.~~Bonnie
>foreach (Control ctrl in this.Controls) >{ > MessageBox.Show(ctrl.Text); >} >>However I don't know how to get SelectedValue from a combo box or Checked from a check box controls. These properties are not available in the generic ctrl control. I tried to play with GetProperty():
>foreach (Control ctrl in this.Controls) >{ > if (ctrl.GetType().Name == "ComboBox") > MessageBox.Show(ctrl.GetType().GetProperty("SelectedValue").ToString()); >} >>I got System.Object SelectedValue. How can I get the value itself?