public const BindingFlags MemberAccess = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.IgnoreCase ; String MyTextBoxName = "txtCompany"; String ValueToSet = "NewValue"; // *** Get a reference to the TextBox TextBox MyTextBox = (TextBox) this.GetType().GetField(MyTextBox,BindingFlags).GetValue(this,MyTextBoxName); MyTextBox.GetType().GetProperty("Text",BindingFlags).SetValue(MyTextBox,ValueToSet,null);I have checked several times and think I typed in what he suggested accurately. Here's what I tried:
public const BindingFlags MemberAccess = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.IgnoreCase; /// <summary> /// Constructor /// </summary> public PatientMaint(int currentPatientId) { . . . oCoverageType = (CoverageType)this.RegisterBizObj(new CoverageType()); . . . InitializeComponent(); oCoverageType.GetAllData(); int CvgTypeCount = oCoverageType.GetRowCount(); //ArrayList aCvgType = new ArrayList(CvgTypeCount); for (int i = 0; i < CvgTypeCount; i = i + 1) { oCoverageType.DataRow = oCoverageType.DataSet.Tables[0].Rows[i]; string CvgTypeTextBoxName = "txtCoverage" + i.ToString(); TextBox CvgTypeTextBox = (TextBox)this.GetType().GetField(CvgTypeTextBox, BindingFlags).GetValue(this, CvgTypeTextBoxName); CvgTypeTextBox.GetType().GetProperty("Text", MemberAccess).SetValue(CvgTypeTextBox, oCoverageType.Entity.CoverageType, null); //aCvgType.Add(oCoverageType.Entity.CoverageType); }When I try to run this, I get a compile error: 'System.Reflection.BindingFlags' is a 'type' but is used like a 'variable'. Then I tried changing BindingFlags to MemberAccess, thinking that I needed to reference the variable name. When I do that I get the following error: Error 1 The best overloaded method match for 'System.Type.GetField(string, System.Reflection.BindingFlags)' -- Error 2 Argument '1': cannot convert from 'System.Windows.Forms.TextBox' to 'string'
>>* Using the indirect reference >>lcBaseName = "TypeDesc" >>lcRowCount = 1 >>use myTable >>scan >> lcCurrentTextBox = lcBaseName + str(lnRowCount) >> &lcCurrentTextBox.Value = myTable.TypeDesc >>endfor >> >>>>