Avatar of r3nder
r3nder
Flag for United States of America asked on

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

.NET ProgrammingC#ASP.NET

Avatar of undefined
Last Comment
r3nder

8/22/2022 - Mon
UnifiedIS

lblBitTripNum, lblStartingDepth and lblBitToTool all are being set to the same location (new point (68, 17).  Are they supposed to be the same location?
r3nder

ASKER
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
r3nder

ASKER
here is what itt looks like iterated 2XCapture.PNG
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
UnifiedIS

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?
UnifiedIS

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.
r3nder

ASKER
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++;
                }
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
r3nder

ASKER
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

UnifiedIS

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.
r3nder

ASKER
I was thinking about that but I couldn't figure out how to remove all of the controls in this UserControl
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER CERTIFIED SOLUTION
UnifiedIS

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
r3nder

ASKER
Thanks Unified