)
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 display the negative symbol in starting of cell value when RTL mode is enabled in WinForms GridControl?

Platform: WinForms |
Control: GridControl |
Published Date: February 15, 2016 |
Last Revised Date: December 17, 2019

RTL support

By default, in RTL mode the negative symbol will be displayed right side only. Please refer the below image for more information,

                               Negative symbol displayed to right side                   

To display the negative symbol in starting of a cell value when RTL mode is enabled, the following ways can be used, 

             1.DrawCellDisplayText event.

             2.RightToLeft property.

Using DrawCellDisplayText event

In this method, the negative symbol can be displayed in starting of a cell by getting the text without negative symbol using SubString method and adding the modified text using DisplayText property.

Code Snippet

C#

this.gridControl1.DrawCellDisplayText += new GridDrawCellDisplayTextEventHandler(gridControl1_DrawCellDisplayText);
 
void gridControl1_DrawCellDisplayText(object sender, GridDrawCellDisplayTextEventArgs e)
{
   if (e.DisplayText.IndexOf('-') != -1 && e.DisplayText.IndexOf('-') == 0)
   {
      string sample = e.DisplayText.Substring(e.DisplayText.IndexOf('-') + 1,  e.DisplayText.Length - 1);
      e.DisplayText = sample + '-';
   }
}

 

VB

AddHandler gridControl1.DrawCellDisplayText, AddressOf gridControl1_DrawCellDisplayText
Private Sub gridControl1_DrawCellDisplayText(ByVal sender As Object, ByVal e As GridDrawCellDisplayTextEventArgs)
   If e.DisplayText.IndexOf("-"c) <> -1 AndAlso e.DisplayText.IndexOf("-"c) = 0 Then
       Dim sample As String = e.DisplayText.Substring(e.DisplayText.IndexOf("-"c) + 1,  e.DisplayText.Length - 1)
       e.DisplayText = sample & "-"c
   End If
End Sub

 

Using RightToLeft property

To display the negative symbol in starting of cell value when RTL mode is enabled can be done by setting RightToLeft property as “No” for needed cells.

C#

void gridControl1_DrawCellDisplayText(object sender, GridDrawCellDisplayTextEventArgs e)
{
   e.Style.RightToLeft = System.Windows.Forms.RightToLeft.No;
}

 

VB

Private Sub gridControl1_DrawCellDisplayText(ByVal sender As Object, ByVal e As GridDrawCellDisplayTextEventArgs)
   e.Style.RightToLeft = System.Windows.Forms.RightToLeft.No;
End Sub

 

Screenshot                         Negative symbol displayed to left side                 

Samples:

C#: Displaying Negative symbol in RTL mode_CS

VB: Displaying Negative symbol in RTL mode_VB

 

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