How to display the negative symbol in starting of cell value when RTL mode is enabled in WinForms GridControl?
RTL support
By default, in RTL mode the negative symbol will be displayed right side only. Please refer the below image for more information,
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
Samples:
C#: Displaying Negative symbol in RTL mode_CS
VB: Displaying Negative symbol in RTL mode_VB