Visual Basic Development Bookmark and Share   
 Home > Visual Basic Power Packs > Can't Anchor control as expected in a DataRepeater
 

Can't Anchor control as expected in a DataRepeater

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.
Steve Roberts  Thursday, July 23, 2009 4:37 PM

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

John Chen MS  Sunday, July 26, 2009 6:38 AM
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
John Chen MS  Sunday, July 26, 2009 6:06 AM

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

John Chen MS  Sunday, July 26, 2009 6:38 AM

Thank you John for your friendly help and support!


Hi Steve,

Welcometo 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.
Martin Xie - MSFT  Thursday, July 30, 2009 9:07 AM
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.
Steve Roberts  Thursday, July 30, 2009 9:34 AM
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.
John Chen MS  Monday, November 02, 2009 7:14 PM

You can use google to search for other answers

Custom Search

More Threads

• Printform and Printing Single Control from the Screen
• Using PrintForm for a scrolling DataGridView
• How to add a unbound data
• Printer Compatibility Library - Rotate Text
• How do I Center a form for Printing using Printform?
• embedded Media Player repeat playlist
• Print to file in power packs 2.0
• The Data Repeater control is released!
• VB & Outlook
• Visual Basic 6.0 Ethernet XML