Hi,
I am trying to implement a custom DataGridCellElement that contains a label and a hyperlink. For both elements I use RadLabelElements with different font styles.
My problem is, that if the cell is too small to hold the whole text of both elements the text of the hyperlink is drawn into the neighboring cell on the right. What is wrong with my code?
(Q1 2011 SP1, .NET 3.5)
Thanks in advance, Christoph
I am trying to implement a custom DataGridCellElement that contains a label and a hyperlink. For both elements I use RadLabelElements with different font styles.
My problem is, that if the cell is too small to hold the whole text of both elements the text of the hyperlink is drawn into the neighboring cell on the right. What is wrong with my code?
(Q1 2011 SP1, .NET 3.5)
Thanks in advance, Christoph
public class HyperlinkCellElement : GridDataCellElement{ private RadLabelElement _headerLabel; private RadLabelElement _linkLabel; public HyperlinkCellElement(GridViewColumn column, GridRowElement row) : base(column, row) {} protected override Type ThemeEffectiveType { get {return typeof(GridDataCellElement); } } public override void Initialize(GridViewColumn column, GridRowElement row) { base.Initialize(column, row); _headerLabel.Text = column.Name; } protected override void CreateChildElements() { _headerLabel = new RadLabelElement(); _headerLabel.Font = new Font(Font, FontStyle.Bold); _headerLabel.Margin = new Padding(0, 2, 0, 0); _headerLabel.LabelText.AutoEllipsis = true; _headerLabel.LabelText.AutoSize = true; _headerLabel.LabelText.AutoSizeMode = RadAutoSizeMode.Auto; _headerLabel.LabelText.TextWrap = false; _linkLabel = new RadLabelElement(); _linkLabel.Font = new Font(Font, FontStyle.Underline); _linkLabel.MouseHover += (s, e) => { if (Cursor.Current == Cursors.Default) Cursor.Current = Cursors.Hand; }; _linkLabel.MouseLeave += (s, e) => { if (Cursor.Current == Cursors.Hand) Cursor.Current = Cursors.Default; }; _linkLabel.Margin = new Padding(0, 2, 0, 0); _linkLabel.LabelText.AutoEllipsis = true; _linkLabel.LabelText.AutoSize = true; _linkLabel.LabelText.AutoSizeMode = RadAutoSizeMode.Auto; _linkLabel.LabelText.TextWrap = false; this.Children.Add(_headerLabel); this.Children.Add(_linkLabel); _linkLabel.Click += new EventHandler(_label_Click); } void _label_Click(object sender, EventArgs e) { //TODO; } protected override void DisposeManagedResources() { _linkLabel.Click -= new EventHandler(_label_Click); base.DisposeManagedResources(); } protected override void SetContentCore(object value) { _linkLabel.Text = value.ToString(); } protected override SizeF ArrangeOverride(SizeF finalSize) { if (this.Children.Count == 2) { var label = this.Children[0]; var link = this.Children[1]; var labelWidth = Math.Min(finalSize.Width, label.DesiredSize.Width); var linkWidth = Math.Min(link.DesiredSize.Width, finalSize.Width - labelWidth); label.Arrange(new RectangleF( 0, (finalSize.Height / 2) - (label.DesiredSize.Height / 2), labelWidth, label.DesiredSize.Height)); link.Arrange(new RectangleF( label.Size.Width, (finalSize.Height / 2) - (link.DesiredSize.Height / 2), linkWidth, link.DesiredSize.Height)); } return finalSize; } public override bool IsCompatible(GridViewColumn data, object context) { return data is GridViewHyperlinkColumn && context is GridDataRowElement; }}