Articles in this section
Category / Section

How to display the negative symbol in starting of cell value when RTL mode is enabled in WinForms GridControl?

1 min read

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

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied