Solved

passing array in tag property of control (C#.net winforms)

Posted on 2006-06-12
2
355 Views
Last Modified: 2012-06-27
I am dynamically building controls on a screen and need to attach some values for later reference to each control.  I attached an array of 2 values to each control through the Tag property.  So now I'm where I need to get those values out but I cannot figure out the syntax to access them.  Sorry if this is a lame question...I'm new at C#.net.  This is how I attached them:

                string[] strCtrlArray = new string[2];
                strCtrlArray[0] = strReportParameterName;
                strCtrlArray[1] = strParmCtrlProperty;

                    Type ctype = Type.GetType(strClsName);
                    objCtrl = Activator.CreateInstance(ctype);

                    strProp = "Tag";
                    pinf = ctype.GetProperty(strProp);
                    pinf.SetValue(objCtrl, strCtrlArray, null);
                   
                    this.Controls.Add(objCtrl as Control);

I know the values are there in an array because I can see them in debug.    But I can't figure out the syntax to get them out.

Thank you so much for your help!                
0
Comment
Question by:babybird
2 Comments
 
LVL 18

Accepted Solution

by:
Ravi Singh earned 125 total points
ID: 16890169
Assuming you have the control object then you'll just have to cast the tag properties' value back to a string array:

string[] array = (string[]) objCtrl.Tag;
0
 

Author Comment

by:babybird
ID: 16890208
Thank you so much! That worked!
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Question! 4 36
Add different cell to otherwise similiar row 4 39
Getting error in connectionstring with Excel. 30 31
C# winforms programmitically move panels 6 29
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question