)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to resolve the text position in edit mode when the text vertical alignment is in middle?

Platform: WinForms |
Control: GridControl |
Published Date: July 9, 2015 |
Last Revised Date: December 20, 2019

Resolve the moving text position

The text position getting changed in edit mode is the default behavior of Grid Control. The difference in text position is viewable when the vertical alignment is set to middle and the row height is increased.

Solution

This is because, even the row height has been changed, and the text position remains the same. To fix this, you have to set the position of cell text depending on the row height in QueryCellInfo event.

C#

//Form Load
//increase the rowheight
this.grid.DefaultRowHeight = 35;
//Set the vertical alignment to Middle
this.grid.TableStyle.VerticalAlignment = GridVerticalAlignment.Middle;
this.grid.QueryCellInfo += new GridQueryCellInfoEventHandler(gridControl1_QueryCellInfo);
 
void gridControl1_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
   if (e.Style.CellType == GridCellTypeName.TextBox && this.grid.CurrentCell.HasCurrentCellAt(e.RowIndex,e.ColIndex))
   {
     //to adjust the text position in edit mode.
     e.Style.TextMargins.Top = System.Convert.ToInt32(this.grid.RowHeights[e.RowIndex] / 3);
   }
}

 

VB

'Form Load
'increase the rowheight
Me.grid.DefaultRowHeight = 40
'Set the vertical alignment to Middle
Me.grid.TableStyle.VerticalAlignment = GridVerticalAlignment.Middle
 
AddHandler grid.QueryCellInfo, AddressOf gridControl1_QueryCellInfo
 
Private Sub gridControl1_QueryCellInfo(ByVal sender As Object, ByVal e As GridQueryCellInfoEventArgs)
  'to adjust the text position in edit mode.
  If e.Style.CellType Is GridCellTypeName.TextBox AndAlso          Me.grid.CurrentCell.HasCurrentCellAt(e.RowIndex, e.ColIndex)
 Then
    e.Style.TextMargins.Top = sSystem.Convert.ToInt32(Me.grid.RowHeights(e.RowIndex) / 3)
  End If
End Sub

 

Screenshot:

Show the text position in grid cell

 

Samples:

C#: TextPositioninEditmode

VB: TextPositioninEditmode

 

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon