|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
object componentthe ImageUrl of various ImageButtons in response to the text contained in corresponding label controls. The following code works: PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(this.ImageButton12); PropertyDescriptor myProperty = properties.Find("ImageUrl", false); myProperty.SetValue(ImageButton12,@"C:\Inetpub\wwwroot\BB\images\X.BMP") Now I want to replace all references to "ImageButton12" in the above code with a member of an array such as "pram[2]" so that I can loop through all the ImageBoxes easily in code. Where: string[] pram = new string[] {"Label33","Label34","Label35","Label36","Label37","Label38","Label39"}; or string[] pram = new string[] {"this.Label33","this.Label34","this.Label35"," this.Label36"," this.Label37"," this.label38"," this.Label39"}; or Object[] pram = new Object[] {"this.Label33","this.Label34","Label35","Label36","Label37","Label38","Label39"}; Each time a get an "Object reference not set to an instance of an object" error. I have even tried changing the array to a component array, but then I get a "Can't implicitly change type" error. The data type specified is "object component" I need to build an array of object components that I can address by index number. Any insight would be appreciated. Thanks, Jim Although I'm more a VB programmer, I think I know the answer:
(correct me if I'm wrong) in the line : myProperty.SetValue(ImageButton12,@"C:\Inetpub\wwwroot\BB\images\X.BMP") ImageButton12 is a object, in this case a button. What you are trying to do is to replace a button-object with a string. The setvalue method then does not recognize it as an object and gives an error. rg. Eric Show quote "Jim McGivney" <mcgiv1@no-spam.sbcglobal.net> schreef in bericht news:u6RZQDF%23FHA.1140@tk2msftngp13.phx.gbl... > On an aspx page with C# code behind I am trying to programmatically change > the ImageUrl of various ImageButtons in response to the text contained in > corresponding label controls. > > > > The following code works: > > > > PropertyDescriptorCollection properties = > TypeDescriptor.GetProperties(this.ImageButton12); > > > > PropertyDescriptor myProperty = properties.Find("ImageUrl", false); > > > > myProperty.SetValue(ImageButton12,@"C:\Inetpub\wwwroot\BB\images\X.BMP") > > > > > > Now I want to replace all references to "ImageButton12" in the above code > with a member of an array such as "pram[2]" so that I can loop through > all the ImageBoxes easily in code. > > > > Where: > > > > string[] pram = new string[] > {"Label33","Label34","Label35","Label36","Label37","Label38","Label39"}; > > > > or > > > > string[] pram = new string[] > {"this.Label33","this.Label34","this.Label35"," this.Label36"," > this.Label37"," this.label38"," this.Label39"}; > > > > or > > > > Object[] pram = new Object[] > {"this.Label33","this.Label34","Label35","Label36","Label37","Label38","Label39"}; > > > > > > Each time a get an "Object reference not set to an instance of an object" > error. > > > > I have even tried changing the array to a component array, but then I get > a "Can't implicitly change type" error. > > > > The data type specified is "object component" I need to build an array of > object components that I can address by index number. > > > > Any insight would be appreciated. > > Thanks, > > Jim > > > > > > > > |
|||||||||||||||||||||||