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?
 
UnifiedISCommented:
There is a clear method on the controls collection
pnlMain.Controls.Clear;
0
 
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
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
r3nderAuthor Commented:
here is what itt looks like iterated 2XCapture.PNG
0
 
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
 
r3nderAuthor Commented:
Thanks Unified
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.