Solved

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

Posted on 2006-06-12
2
337 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
I need C# converted to VB.net 1 53
How to read XML file attributes... 17 41
.NET Error 7 42
c# code 19 59
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now