.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

how to get goupboxname when i click button

Posted By: rashmi     Posted Date: May 13, 2011    Points:5   Category :C#
i have code which create groupbox and button dynamically in this coding when i click button i need to know the groupbox name also, how can i do this

below is the code:

panel1.Controls.Clear();
this.BackColor = ColorTranslator.FromHtml("#c8e2f3");
panel1.BackColor = ColorTranslator.FromHtml("#c8e2f3");
DataTable secName = MustardSoftware.Code.Order.GetTableCount();

int groupRightLocatio = 10;

int groupsize;

foreach (DataRow dr in secName.Rows)
{
secid = MustardSoftware.Code.Order.Getsectionid(dr[0].ToString());
int buttonRightLocation = 20;
int buttonLeftLocation = 10;
//buttonLeftLocation = 10;
int count = 1;

label2.Text = dr[0].ToString();
label1.Text = dr[1].ToString();

GroupBox Group1 = new GroupBox();
if (Convert.ToInt16(label1.Text) <= 5)
{
groupsize = 40 * Convert.ToInt16(label1.Text);
}
else
{
groupsize = 10 * Convert.ToInt16(label1.Text);
}
Group1.Location = new Point(20, groupRightLocatio);
Group1.Size = new Size(800, groupsize);
Group1.Text = dr[0].ToString();
panel1.Controls.Add(Group1);
groupRightLocatio = groupRightLocatio + groupsize + 10;
int k;
for (k = 1; k <= Convert.ToInt16(label1.Text); k++)
{
if (k % 12 != 0)
{
buttonLeftLocation = buttonLeftLocation + 60;
}
else
{
buttonLeftLocation = 70;
buttonRightLocation = buttonRightLocation + 60;
}
Button button1 = new Button();

DataTable tblstatus = MustardSoftware.Code.Order.GetTableNoStatus(label2.Text, count);
foreach (DataRow dr1 in tblstatus.Rows)
{
string status = dr1[0].ToString();
//MessageBox.Show(status);
if (status == "False")
{
button1.Text = count.ToString();
//button1.BackColor = ColorTranslator.FromHtml("#803b11");

button1.BackgroundImage = MustardSoftware.Properties.Resources.booktable;
button1.BackgroundImageLayout = ImageLayout.Stretch;
button1.ForeColor = ColorTranslator.FromHtml("#fcfffc");
button1.TextAlign = System.Drawing.ContentAlignment.TopCenter;
button1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold);
}
else
{
button1.Text = count.ToString();
//button1.BackColor = ColorTranslator.FromHtml("#0d5d0f");

button1.BackgroundImage = MustardSoftware.Properties.Resources.freetable;
button1.BackgroundImageLayout = ImageLayout.Stretch;
button1.ForeColor = ColorTranslator.FromHtml("#ffffff");
button1.TextAlign = System.Drawing.ContentAlignment.TopCenter;
button1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold);
}
}


button1.AccessibleName = secid.ToString();
button1.Name = count.ToString();
button1.Location = new Point(buttonLeftLocation, buttonRightLocation);
button1.Size = new Size(50, 50);
button1.Click += new EventHandler(button1_Click);
Group1.Controls.Add(button1);
count = count + 1;
tblName[k] = new object();
tblName[k] = button1;
//string s = tblName.ToString ();
//MessageBox.Show(s);
}

//string str = "";
//for (k = 1; k <= Convert.ToInt16(label1.Text); k++)
//{
// str = str + ((Button)tblName[k]).Name;
//}
//MessageBox.Show(str);
}

Responses
Author: Narayanan             
Posted Date: September 07, 2011     Points: 20   

Hi ,
set tabindex of textbox and use .Controls.Indexofkey
Regards,
Lakshmi Narayanan.S

Regards, Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend