Welcome to Dream.In.Code
Become an Expert!

Join 149,602 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,905 people online right now. Registration is fast and FREE... Join Now!




Help adding controls dynamically

 
Reply to this topicStart new topic

Help adding controls dynamically

phannon666
12 Oct, 2007 - 02:36 AM
Post #1

New D.I.C Head
*

Joined: 12 Oct, 2007
Posts: 4


My Contributions
Hi there, I have a similar issue. I'm attempting to load some SQL data to a dynamic table, all the data loads fine, the problem is formatting the layout of two particular cells. I understand whats going on, but cannot find a solution. What i'm attempting to do is for each text item in this particular db (loaded into an array) list the text, and beneath each item, display a button. The problem is it will only do this correct format for the last item, as it is getting overwritten. So I think what I need to be doing is appending to this cell somehow, thanks in advance for any further help. As you will see its not the best of code atm but its been mashed and mixed so many times, any questions about my code will be quickly responded to.

Pete.

CODE
for (int i = 0; i < 4; i++)
            {
                TableRow tr = new TableRow();
                tr.BorderWidth = 1;
                TableRow r = new TableRow();
                r.BorderWidth = 1;
                TableCell tc = new TableCell();
                tc.BorderWidth = 1;
                TableCell tc2 = new TableCell();
                tc2.BorderWidth = 1;
                TableCell tcb = new TableCell();
                tcb.BorderWidth = 1;
                tc2.Width = 400;
                Label l = new Label();
                l.Font.Bold = true;
                Label l2 = new Label();              

                if (!(cemsDescArray[f].Equals(0)))
                {
                    if (i.Equals(0))
                    {
                        l.Text = "CEMS ID: ";
                        l2.Text = cemsDescArray[a].ToString();
                        a++;
                        tc.Controls.Add(l);
                        tc2.Controls.Add(l2);
                        r.Cells.Add(tc);
                        r.Cells.Add(tc2);
                    }
                    if (i.Equals(1))
                    {
                        l.Text = "Summary: ";
                        String x = (string)descArray[b];
                        String newT = x.Replace("##APO##", "\'");
                        l2.Text = newT;
                        b++;
                        tc.Controls.Add(l);
                        tc2.Controls.Add(l2);
                        r.Cells.Add(tc);
                        r.Cells.Add(tc2);
                    }
                    if (i.Equals(2))
                    {
                        l.Text = "Description: ";
                        String xx = "";
                        newX = "";
                        tc.Controls.Add(l);
                        r.Cells.Add(tc);
                        foreach (String str in extDescArray)
                        {
                            xx += str + "<br/><br/>";
                            newX = xx.Replace("##APO##", "\'");
                            l2.Text = newX;
                            //tc2 = new TableCell();
                            editInfo = new Button();
                            editInfo.Attributes.Add("AutoPostBack", "true");
                            editInfo.Text = "Edit Description";
                            editInfo.Click += new EventHandler(editInfo_Click);

                            tc2.Controls.Add(l2);
                            tc2.Controls.Add(editInfo);
                            r.Cells.Add(tc2);
                        }                                            
                        c++;
                    }
                    if (i.Equals(3))
                    {                      
                        l.Text = "Solution: ";
                        String xxx = "";
                        newTe = "";
                        tc.Controls.Add(l);
                        r.Cells.Add(tc);
                        foreach (String str in solutionsArray)
                        {
                            xxx += str + "<br/><br/>";
                            newTe = xxx.Replace("##APO##", "\'");
                            l2.Text = newTe;
                            //tc2 = new TableCell();
                            editSolution = new Button();
                            editSolution.Attributes.Add("AutoPostBack", "true");
                            editSolution.Text = "Edit Solution";
                            editSolution.Click += new EventHandler(editSolution_Click);
                            
                            tc2.Controls.Add(l2);
                            tc2.Controls.Add(editSolution);
                            r.Cells.Add(tc2);
                        }                                            
                        d++;
                        f++;
                    }

                    tc.HorizontalAlign = HorizontalAlign.Left;
                    tc.VerticalAlign = VerticalAlign.Top;                  
                    //r.Cells.Add(tc);
                    //r.Cells.Add(tc2);
                    table1.Rows.Add(r);
                }
            }            

            form1.Controls.Add(table1);


User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Help Adding Controls Dynamically
12 Oct, 2007 - 04:04 AM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,482



Thanked: 161 times
Dream Kudos: 9050
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
@phannon666, I split this into its own topic because
  1. Its never nice to take over someone else's thread with your question (even though they may be similar)
  2. History shows you'll get a better response if you open your own thread
    • This doesn't count with like this video and song of the day threads and similar here

Once Ive had a chance to drink some coffee Ill look over your code and try to help smile.gif
User is offlineProfile CardPM
+Quote Post

phannon666
RE: Help Adding Controls Dynamically
12 Oct, 2007 - 04:31 AM
Post #3

New D.I.C Head
*

Joined: 12 Oct, 2007
Posts: 4


My Contributions
QUOTE(PsychoCoder @ 12 Oct, 2007 - 05:04 AM) *

@phannon666, I split this into its own topic because
  1. Its never nice to take over someone else's thread with your question (even though they may be similar)
  2. History shows you'll get a better response if you open your own thread
    • This doesn't count with like this video and song of the day threads and similar here
Once Ive had a chance to drink some coffee Ill look over your code and try to help smile.gif


ty, sorry I'm used to the whole "always better to post in an existing thread than start a new one" but meh, look forward to your response, I'm gonna get a lemsip lol

User is offlineProfile CardPM
+Quote Post

phannon666
RE: Help Adding Controls Dynamically
16 Oct, 2007 - 06:49 AM
Post #4

New D.I.C Head
*

Joined: 12 Oct, 2007
Posts: 4


My Contributions
Hey, sorry havn't been around in a few days. Did you manage to have a look at my code?

Cheers

User is offlineProfile CardPM
+Quote Post

phannon666
RE: Help Adding Controls Dynamically
22 Oct, 2007 - 12:53 AM
Post #5

New D.I.C Head
*

Joined: 12 Oct, 2007
Posts: 4


My Contributions
hello??
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 11:48PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month