This is a migrated thread and some comments may be shown as answers.

Cell Sizing in Custom Cell

1 Answer 102 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Phillip
Top achievements
Rank 1
Phillip asked on 09 Sep 2009, 04:36 PM
Hi,

I have a custom cell layout, similar to a Business Card, and it lays out exactly correctly. However I want to instruct the grid to obey a minimum size for the cell, but I cannot seem to get it right.

Heres my code from the custom GridDataCellElement - I wonder if you can spot the problem or sugges a better way of forcing a minumum cell size ?

Thanks.
 protected override void CreateChildElements()  
            {  
                base.CreateChildElements();  
                this.pictureBox = new Telerik.WinControls.UI.RadButtonElement();  
                this.pictureBox.MinSize = new Size(150, 150);  
                this.pictureBox.Size = this.pictureBox.MinSize;  
                this.pictureBox.AutoSize = false;  
                this.Children.Add(this.pictureBox);  
 
                this.dataLabelsAndValues = new List<Telerik.WinControls.RadElement>();  
                  
                foreach(string propertyName in column.ColumnDefinition.SelectedFields)  
                {  
                    iSIMS.DataModel.SimpleProperty fieldDefinition = iSIMS.DataEntity.DataEntity.DataModel.GetField<iSIMS.DataModel.SimpleProperty>(propertyName);  
                    if (fieldDefinition != null)  
                    {  
                        Telerik.WinControls.UI.RadLabelElement label = new Telerik.WinControls.UI.RadLabelElement();  
                        label.Text = fieldDefinition.Description;  
                        label.Font = new Font(label.Font, FontStyle.Bold);  
                        label.MinSize = new Size(100, 20);  
                        label.Size = label.MinSize;  
                        label.AutoSize = false;  
                        dataLabelsAndValues.Add(label);  
 
                        Telerik.WinControls.UI.RadLabelElement textBox = new Telerik.WinControls.UI.RadLabelElement();  
                        textBox.Tag = propertyName;  
                        textBox.AutoSize = false;  
                        textBox.MinSize = new Size(100, 20);  
                        textBox.Size = textBox.MinSize;  
                        dataLabelsAndValues.Add(textBox);  
                    }  
                }  
                this.Children.AddRange(dataLabelsAndValues.ToArray());  
                  
            }  
 
            protected override SizeF ArrangeOverride(SizeF finalSize)  
            {  
                SizeF size = base.ArrangeOverride(finalSize);  
                RectangleF clientRect = GetClientRectangle(finalSize);  
                int controlOffset = 0;  
                int maxWidth = 0;  
                int maxHeight = 0;  
                foreach (Telerik.WinControls.RadElement element in this.Children)  
                {  
                    if (element == pictureBox)  
                    {  
                        element.Arrange(  
                            new RectangleF(  
                                clientRect.Left+5,  
                                clientRect.Top+5,  
                                150,  
                                150)  
                                );  
                    }  
                    else 
                    {  
 
                        element.Arrange(  
                            new RectangleF(  
                                clientRect.Left + 150 + 5 +5,  
                                clientRect.Top + (controlOffset * 20) +5,  
                                clientRect.Width - (150 + 5),  
                                20)  
                                );  
                                  
                        controlOffset++;  
                    }  
 
                      
                }  
 
                return size;  
            }    
 

1 Answer, 1 is accepted

Sort by
0
Accepted
Jack
Telerik team
answered on 10 Sep 2009, 02:30 PM
Hello Phillip,

You have to set a minimum height for the row and a minimum width for the column. Please check the following code snippet:

this.radGridView1.Columns["Name"].MinWidth = 150; 
this.radGridView1.Columns["Name"].Width = 150; 
 
void radGridView1_CreateRow(object sender, GridViewCreateRowEventArgs e) 
    if (e.RowInfo is GridViewDataRowInfo) 
    { 
        e.RowInfo.MinHeight = 150; 
        e.RowInfo.Height = 150; 
    } 

Another option is to set the AutoSizeRows property to true and to return your desired size by overriding the MeasureOverride method:

public class MyCell : GridDataCellElement 
    protected override SizeF MeasureOverride(SizeF availableSize) 
    { 
        return new Size(100, 100); 
    } 

I hope this helps.

Regards,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Phillip
Top achievements
Rank 1
Answers by
Jack
Telerik team
Share this question
or