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

GridViewComboBoxColumn Editor Alignment

1 Answer 85 Views
GridView
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 20 Jun 2017, 02:11 PM

I have a GridViewComboBoxColumn and while in edit mode I want the StretchVertically to be false so I use the following code:

this.radGridView1.CellBeginEdit += RadGridView1_CellBeginEdit;

private void RadGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e)
{
switch (e.Column.Name)
{
case "MyColumn":
RadDropDownListEditor editor = e.ActiveEditor as RadDropDownListEditor;
if (editor != null)
{
editor.EditorElement.StretchVertically = false;
editor.EditorElement.Alignment = ContentAlignment.TopLeft;
}

But the dropdownlisteditor is still vertically centered in the cell. Is there a way to have it TopLeft?

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 21 Jun 2017, 10:52 AM
Hello David,

You need to create a custom column and override the ArrangeEditorElement method. Here is a sample implementation:
public class CustomColumn : GridViewComboBoxColumn
{
    public override Type GetCellType(GridViewRowInfo row)
    {
        if (row is GridViewDataRowInfo)
        {
            return typeof(MyCell);
        }
        return base.GetCellType(row);
    }
}
class MyCell : GridComboBoxCellElement
{
    public MyCell(GridViewColumn col, GridRowElement row) : base(col, row)
    { }
    protected override Type ThemeEffectiveType
    {
        get
        {
            return typeof(GridComboBoxCellElement);
        }
    }
    protected override void ArrangeEditorElement(SizeF finalSize, RectangleF clientRect)
    {
        RadElement element = this.GetEditorElement(Editor);
        float editorHeight = element.DesiredSize.Height;
        if (element.StretchVertically)
        {
            editorHeight = clientRect.Height;
        }
        editorHeight = Math.Min(editorHeight, finalSize.Height);
 
        if (ViewTemplate.ViewDefinition is HtmlViewDefinition && ControlBoundingRectangle.X < 0)
        {
            clientRect.X += -ControlBoundingRectangle.X;
        }
 
        RectangleF editorRect = new RectangleF(clientRect.X, clientRect.Y, clientRect.Width, editorHeight);
        element.Arrange(editorRect);
    }
}

Please let me know if there is something else I can help you with. 
 
Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
GridView
Asked by
David
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or