Visual Basic > Visual Basic Forums > Visual Basic Power Packs > Can't Anchor control as expected in a DataRepeater
Ask a questionAsk a question
 

AnswerCan't Anchor control as expected in a DataRepeater

  • Thursday, July 23, 2009 4:37 PMSteve Roberts Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I have a data repeater (vertical mode) where I have some labels/textboxes that need to be top + right anchored so that they stay their original size but remain aligned to the right side as the data repeater grows/shrinks.

    If I set top + right anchors on any label/textbox then it dissapears from the form, presumably they're off the right hand side in space.

    If I set left + top + rigtht anchors then they stay in position but grow/shrink, which is not the required effect.

    I've also tried using a panel control docked full in the data repeater with my control on the panel but get the same problem.

Answers

  • Sunday, July 26, 2009 6:38 AMJohn Chen MSModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Played it again and I found that you can workaround with the this.dataRepeater1.ItemCloned event like this: 

    C#:  
                this.dataRepeater1.ItemCloned +=new Microsoft.VisualBasic.PowerPacks.DataRepeaterItemEventHandler(dataRepeater1_ItemCloned); 

            private void dataRepeater1_ItemCloned(object sender,
        Microsoft.VisualBasic.PowerPacks.DataRepeaterItemEventArgs e)
            {
                Button b1 = (Button)dataRepeater1.ItemTemplate.Controls["button1"];
                b1.Left = 100; // set what ever value you want 
                b1.Top = 20; // set what ever value you want 
            }

    HTH,

    John

All Replies

  • Sunday, July 26, 2009 6:06 AMJohn Chen MSModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Steve,

    This appear to be a bug in the datarepeater. I will follow up the team in Microsoft to investigate it.
    At the mean time, I think a work around is to put your control (maybe group in a panel control if there is many) about 300 pixiels left of the desired location at design time.

    John
  • Sunday, July 26, 2009 6:38 AMJohn Chen MSModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Played it again and I found that you can workaround with the this.dataRepeater1.ItemCloned event like this: 

    C#:  
                this.dataRepeater1.ItemCloned +=new Microsoft.VisualBasic.PowerPacks.DataRepeaterItemEventHandler(dataRepeater1_ItemCloned); 

            private void dataRepeater1_ItemCloned(object sender,
        Microsoft.VisualBasic.PowerPacks.DataRepeaterItemEventArgs e)
            {
                Button b1 = (Button)dataRepeater1.ItemTemplate.Controls["button1"];
                b1.Left = 100; // set what ever value you want 
                b1.Top = 20; // set what ever value you want 
            }

    HTH,

    John

  • Thursday, July 30, 2009 9:07 AMMartin Xie - MSFTMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Thank you John for your friendly help and support!


    Hi Steve,

    Welcome to MSDN forums!



    Best regards,
    Martin Xie



    Does this help? If you have any future questions or concerns, please feel free to let us know.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
  • Thursday, July 30, 2009 9:34 AMSteve Roberts Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Thanks for your reply John, but from the workaround you describe it sounds like I can't take advantage of automatic positioning via the anchor property of a control (either in or out of a host panel) and instead need to calculate the position of the control relative to something else (the datarepeater width ?)

    I'm going to try the first suggestion (300 pixel offset) first and then if that doesn't work will try using the ItemCloned event.

    More news on this shortly...

    Regards,

    Steve.
  • Monday, November 02, 2009 7:14 PMJohn Chen MSModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    A better workaround provided by YunFeng: Put a Panel inside the DataRepeaterItem and set its Dock property to DockStyle.Fill.  
    John Chen -- See my team blog: http://blogs.msdn.com/vsdata. All my posts are provided "AS IS" with no warranties, and confer no rights.