Home Forums WinForms controls Xceed Grid for WinForms Editors content vertical alignment Reply To: Editors content vertical alignment

Xceed Support
Member
Post count: 5658

Hi Frederico,

To keep the content vertically centered even in edition, you could use the following code sample.

 

Example:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Xceed.Grid;
using Xceed.Grid.Editors;
using Xceed.Editors;
using Xceed.Grid.Viewers;

namespace _26771
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            Xceed.Grid.Licenser.LicenseKey = “”;
            InitializeComponent();

            Column column0 = new Column(“Test”, typeof(string));
            this.grid.Columns.Add(column0);
            this.grid.DataRowTemplate.Height = 50;
            this.grid.DataRowTemplate.OverrideUIStyle = true;
            this.grid.DataRowTemplate.VerticalAlignment = VerticalAlignment.Center;
            CellEditorManager cellEditorManager = this.grid.Columns[“Test”].CellEditorManager;
            
            WinTextBox winTextBox = cellEditorManager.TemplateControl as WinTextBox;
            cellEditorManager.QueryEditorBounds += new QueryEditorBoundsEventHandler(cellEditorManager_QueryEditorBounds);
            for (int i = 0; i < 100; ++i)
            {
                Xceed.Grid.DataRow row = this.grid.DataRows.AddNew();
                row.Cells[“Test”].Value = i.ToString();
            }
        }

        void cellEditorManager_QueryEditorBounds(object sender, QueryEditorBoundsEventArgs e)
        {
            TextEditor textEditor = sender as TextEditor;
            e.Bounds = new Rectangle(e.Bounds.X, e.Bounds.Y + (e.Bounds.Height – ((WinTextBox)e.Control).TextBoxArea.PreferredHeight) / 2, e.Bounds.Width, e.Bounds.Height);
        }
    }
}

Imported from legacy forums. Posted by Mohamed [Xceed] (had 1068 views)