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.
Answers
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- Proposed As Answer byMartin Xie - MSFTMSFT, ModeratorThursday, July 30, 2009 9:05 AM
- Marked As Answer byMartin Xie - MSFTMSFT, ModeratorThursday, August 13, 2009 3:13 AM
All Replies
- 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 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- Proposed As Answer byMartin Xie - MSFTMSFT, ModeratorThursday, July 30, 2009 9:05 AM
- Marked As Answer byMartin Xie - MSFTMSFT, ModeratorThursday, August 13, 2009 3:13 AM
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.- 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. - 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.


