Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Change property of a Control on a Form

$
0
0

I have a data table with single column "ControlName" containing a list of different types of controls on a from. I used the following code to find the Control on the form.

DataTable dt = new DataTable();
                dt.Columns.Add("ControlName", typeof(string));
                dt.Load(dreader);
                for (int i = 0; i < dt.Rows.Count; i++)
                    {
                    var myControlOnFormIs = this.Controls.Find(StringControlName, true);


                    for (int j = 0; j < dt.Rows.Count; j++)
                        {
// HERE WANT TO USE THE BELOW LINE TO ENABLE OR DISABLE THE CONTROL                            
                            this.Controls[myControlOnFormIs.ToString()].Enabled = false;
                        }
}

As mentioned in the code, I want to find the CONTROL on the form and than enable/disable.

But I am getting the following error;

"Object reference not set to an instance of an object."


Please guide...

Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>