label not updating

I wrote some code that creates a set of panels for each List<MyStruct>  in a list. In these panels I added an edit button. when I  click that edit button - it pulls up the record for that set of panels and labels and I allow the user to edit that record. when I update the database I reload the list. and then Iterate through the code to update the 2 labels That could be changed. The only problem is that if it it the last set of panels and labels it will update - if it is not it wont - but the list that was reloaded sees the change. my question is how can I fix this
            if (reset == false) //if it is not an update load the panels - if it is an update go to else
            {
                foreach (var trip in BitTrips)
                {

                    pnlMain = new RadPanel();//pnlMain
                    pnlMain.Name = "pnlMain_" + counter.ToString();
                    pnlMain.Height = 100;
                    pnlMain.Width = 607;

                    int newY = 44;
                    if (counter >= 1)
                    {
                        newY += 110;
                        pnlMain.Location = new Point(66, newY);
                    }
                    else
                    {
                        pnlMain.Location = new Point(66, 44);
                    }
                    pnlMain.BackColor = Color.Black;
                    //
                    pnlBitTripNumber = new RadPanel();//pnlBitTripNumber
                    pnlBitTripNumber.Name = "pnlBitTripNumber" + counter.ToString();
                    pnlBitTripNumber.Width = 202;
                    pnlBitTripNumber.Height = 50;
                    pnlBitTripNumber.Text = "Bit Trip Number";
                    pnlBitTripNumber.TextAlignment = ContentAlignment.TopLeft;
                    pnlBitTripNumber.Location = new Point(0, 0);
                    lblBitTripNum = new RadLabel();//lblBitTripNum
                    lblBitTripNum.Name = "lblBitTripNum" + counter.ToString();
                    lblBitTripNum.Text = trip.BitTripNumber.ToString();
                    lblBitTripNum.Location = new Point(68, 17);
                    pnlBitTripNumber.Controls.Add(lblBitTripNum);
                    pnlMain.Controls.Add(pnlBitTripNumber);
                    //
                    pnlStartingDepth = new RadPanel();//pnlStartingDepth
                    pnlStartingDepth.Name = "pnlStartingDepth" + counter.ToString();
                    pnlStartingDepth.Width = 202;
                    pnlStartingDepth.Height = 50;
                    pnlStartingDepth.TextAlignment = ContentAlignment.TopLeft;
                    pnlStartingDepth.Text = "Starting Depth";
                    pnlStartingDepth.Location = new Point(202, 0);
                    lblStartingDepth = new RadLabel();//lblStartingDepth
                    lblStartingDepth.Location = new Point(68, 17);
                    lblStartingDepth.Name = "lblStartingDepth" + counter.ToString();
                    lblStartingDepth.Text = trip.StartingDepth.ToString();
                    pnlStartingDepth.Controls.Add(lblStartingDepth);
                    pnlMain.Controls.Add(pnlStartingDepth);
                    //
                    pnlBitToTool = new RadPanel();//pnlBitToTool
                    pnlBitToTool.Name = "pnlBitToTool" + counter.ToString();
                    pnlBitToTool.Width = 202;
                    pnlBitToTool.Height = 50;
                    pnlBitToTool.Location = new Point(404, 0);
                    pnlBitToTool.Text = "Bit To Tool Offset";
                    pnlBitToTool.TextAlignment = ContentAlignment.TopLeft;
                    lblBitToTool = new RadLabel();//lblBitToTool
                    lblBitToTool.Name = "lblBitToTool" + counter.ToString();
                    lblBitToTool.Text = trip.BitToToolOffset.ToString();
                    lblBitToTool.Location = new Point(68, 17);
                    pnlBitToTool.Controls.Add(lblBitToTool);
                    pnlMain.Controls.Add(pnlBitToTool);
                    //
                    pnlCreatedOn = new RadPanel();//pnlCreatedOn
                    pnlCreatedOn.Name = "pnlCreatedOn" + counter.ToString();
                    pnlCreatedOn.TextAlignment = ContentAlignment.TopLeft;
                    pnlCreatedOn.Text = "Created On";
                    pnlCreatedOn.Width = 557;
                    pnlCreatedOn.Height = 50;
                    pnlCreatedOn.Location = new Point(0, 50);
                    lblCreatedOn = new RadLabel();//lblCreatedOn
                    lblCreatedOn.Name = "lblCreatedOn" + counter.ToString();
                    lblCreatedOn.Text = trip.BitTripStarted.ToString();
                    lblCreatedOn.Location = new Point(273, 15);
                    pnlCreatedOn.Controls.Add(lblCreatedOn);
                    pnlMain.Controls.Add(pnlCreatedOn);
                    //
                    pnlEdit = new RadPanel();
                    pnlEdit.Name = "pnlEdit" + counter.ToString();
                    pnlEdit.Width = 49;
                    pnlEdit.Height = 50;
                    pnlEdit.Text = string.Empty;
                    //int newY = 50;
                    pbEdit = new PictureBox();
                    pbEdit.Name = "pbEdit" + counter.ToString();
                    pbEdit.Tag = trip.BitTripUID.ToString();
                    pbEdit.Image = Properties.Resources.Edit_Button;
                    pnlEdit.Location = new Point(557, 50);
                    pbEdit.Click += new EventHandler(EditBitTrip);
                    pnlEdit.Controls.Add(pbEdit);
                    pnlMain.Controls.Add(pnlEdit);
                    this.Controls.Add(pnlMain);
                    counter++;


                }
            }
            else //if I changed the list go here to update the 2 labels
            {
                counter = 0;
                foreach (var trip1 in BitTrips)
                {
                    ////pnlBitToTool.Name = "pnlBitToTool" + counter.ToString();
                    lblBitToTool.Text = trip1.BitToToolOffset.ToString();
                    ////lblStartingDepth.Name = "lblStartingDepth" + counter.ToString();
                    lblStartingDepth.Text = trip1.StartingDepth.ToString();
                    //this.Invalidate();
                    //counter++;
                }
                reset = false;
                lblStartingDepth.Invalidate();
                lblBitToTool.Invalidate();
            }

Open in new window

LVL 6
r3nderAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

UnifiedISCommented:
lblBitTripNum, lblStartingDepth and lblBitToTool all are being set to the same location (new point (68, 17).  Are they supposed to be the same location?
0
r3nderAuthor Commented:
yes because they are in a panel
for example
//The Label added to a point in a panel
lblBitTripNum.Location = new Point(68,17)
//add it to the panel
pnlBitTripNumber.Controls.Add(lblBitTripNum);

you will notice that newY adds 110 to the last pnlMain location so it can create another set of panels at a new location
0
r3nderAuthor Commented:
here is what itt looks like iterated 2XCapture.PNG
0
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

UnifiedISCommented:
gotcha.
How did you determine that it will work only when the "last" panel is updated?
If you move the code around so a different panel is last, does it still update the last panel or does it update the original last panel?
0
UnifiedISCommented:
Ok, I have an idea. In the "else" section, you are ferencing the objects: lblBittoTool and lblStartingDepth.  These would represent the labels added last. I don't see how it would go in to each panel and change the values accordingly.
0
r3nderAuthor Commented:
I was thinking since I named them with a counter that it would know which label
counter = 0;
foreach (var trip1 in BitTrips)
                {
                    pnlBitToTool.Name = "pnlBitToTool" + counter.ToString();
                    lblBitToTool.Text = trip1.BitToToolOffset.ToString();
                    lblStartingDepth.Name = "lblStartingDepth" + counter.ToString();
                    lblStartingDepth.Text = trip1.StartingDepth.ToString();
                    //this.Invalidate();
                    counter++;
                }
0
r3nderAuthor Commented:
this is the whole method
        private void BuildBitTripPanels()
        {
            JobID = 10299;
            int counter = 0;
            BitTrips = new List<CompanyRTDatabase.BitTrip>();
            BitTrips = irtd.GetBitTripList(JobID);

            if (reset == false)
            {
                foreach (var trip in BitTrips)
                {

                    pnlMain = new RadPanel();//pnlMain
                    pnlMain.Name = "pnlMain_" + counter.ToString();
                    pnlMain.Height = 100;
                    pnlMain.Width = 607;

                    int newY = 44;
                    if (counter >= 1)
                    {
                        newY += 110;
                        pnlMain.Location = new Point(66, newY);
                    }
                    else
                    {
                        pnlMain.Location = new Point(66, 44);
                    }
                    pnlMain.BackColor = Color.Black;
                    //
                    pnlBitTripNumber = new RadPanel();//pnlBitTripNumber
                    pnlBitTripNumber.Name = "pnlBitTripNumber" + counter.ToString();
                    pnlBitTripNumber.Width = 202;
                    pnlBitTripNumber.Height = 50;
                    pnlBitTripNumber.Text = "Bit Trip Number";
                    pnlBitTripNumber.TextAlignment = ContentAlignment.TopLeft;
                    pnlBitTripNumber.Location = new Point(0, 0);
                    lblBitTripNum = new RadLabel();//lblBitTripNum
                    lblBitTripNum.Name = "lblBitTripNum" + counter.ToString();
                    lblBitTripNum.Text = trip.BitTripNumber.ToString();
                    lblBitTripNum.Location = new Point(68, 17);
                    pnlBitTripNumber.Controls.Add(lblBitTripNum);
                    pnlMain.Controls.Add(pnlBitTripNumber);
                    //
                    pnlStartingDepth = new RadPanel();//pnlStartingDepth
                    pnlStartingDepth.Name = "pnlStartingDepth" + counter.ToString();
                    pnlStartingDepth.Width = 202;
                    pnlStartingDepth.Height = 50;
                    pnlStartingDepth.TextAlignment = ContentAlignment.TopLeft;
                    pnlStartingDepth.Text = "Starting Depth";
                    pnlStartingDepth.Location = new Point(202, 0);
                    lblStartingDepth = new RadLabel();//lblStartingDepth
                    lblStartingDepth.Location = new Point(68, 17);
                    lblStartingDepth.Name = "lblStartingDepth" + counter.ToString();
                    lblStartingDepth.Text = trip.StartingDepth.ToString();
                    pnlStartingDepth.Controls.Add(lblStartingDepth);
                    pnlMain.Controls.Add(pnlStartingDepth);
                    //
                    pnlBitToTool = new RadPanel();//pnlBitToTool
                    pnlBitToTool.Name = "pnlBitToTool" + counter.ToString();
                    pnlBitToTool.Width = 202;
                    pnlBitToTool.Height = 50;
                    pnlBitToTool.Location = new Point(404, 0);
                    pnlBitToTool.Text = "Bit To Tool Offset";
                    pnlBitToTool.TextAlignment = ContentAlignment.TopLeft;
                    lblBitToTool = new RadLabel();//lblBitToTool
                    lblBitToTool.Name = "lblBitToTool" + counter.ToString();
                    lblBitToTool.Text = trip.BitToToolOffset.ToString();
                    lblBitToTool.Location = new Point(68, 17);
                    pnlBitToTool.Controls.Add(lblBitToTool);
                    pnlMain.Controls.Add(pnlBitToTool);
                    //
                    pnlCreatedOn = new RadPanel();//pnlCreatedOn
                    pnlCreatedOn.Name = "pnlCreatedOn" + counter.ToString();
                    pnlCreatedOn.TextAlignment = ContentAlignment.TopLeft;
                    pnlCreatedOn.Text = "Created On";
                    pnlCreatedOn.Width = 557;
                    pnlCreatedOn.Height = 50;
                    pnlCreatedOn.Location = new Point(0, 50);
                    lblCreatedOn = new RadLabel();//lblCreatedOn
                    lblCreatedOn.Name = "lblCreatedOn" + counter.ToString();
                    lblCreatedOn.Text = trip.BitTripStarted.ToString();
                    lblCreatedOn.Location = new Point(273, 15);
                    pnlCreatedOn.Controls.Add(lblCreatedOn);
                    pnlMain.Controls.Add(pnlCreatedOn);
                    //
                    pnlEdit = new RadPanel();
                    pnlEdit.Name = "pnlEdit" + counter.ToString();
                    pnlEdit.Width = 49;
                    pnlEdit.Height = 50;
                    pnlEdit.Text = string.Empty;
                    //int newY = 50;
                    pbEdit = new PictureBox();
                    pbEdit.Name = "pbEdit" + counter.ToString();
                    pbEdit.Tag = trip.BitTripUID.ToString();
                    pbEdit.Image = Properties.Resources.Edit_Button;
                    pnlEdit.Location = new Point(557, 50);
                    pbEdit.Click += new EventHandler(EditBitTrip);
                    pnlEdit.Controls.Add(pbEdit);
                    pnlMain.Controls.Add(pnlEdit);
                    this.Controls.Add(pnlMain);
                    counter++;


                }
            }
            else
            {
                counter = 0;
                foreach (var trip1 in BitTrips)
                {
                    ////pnlBitToTool.Name = "pnlBitToTool" + counter.ToString();
                    lblBitToTool.Text = trip1.BitToToolOffset.ToString();
                    ////lblStartingDepth.Name = "lblStartingDepth" + counter.ToString();
                    lblStartingDepth.Text = trip1.StartingDepth.ToString();
                    //this.Invalidate();
                    //counter++;
                }
                reset = false;
                lblStartingDepth.Invalidate();
                lblBitToTool.Invalidate();
            }

        }

Open in new window

0
UnifiedISCommented:
Instead of only updating the changed labels, why not just rebuild the whole thing from the database? Is it too slow?
If you can't do that, you'll need to reference the labels differently.
0
r3nderAuthor Commented:
I was thinking about that but I couldn't figure out how to remove all of the controls in this UserControl
0
UnifiedISCommented:
There is a clear method on the controls collection
pnlMain.Controls.Clear;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
r3nderAuthor Commented:
Thanks Unified
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.