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 to the image below 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
the DrawCellDisplayText event
In this method, the negative symbol can be displayed in starting of a cell by getting the text without the negative symbol using the SubString method and adding the modified text using the DisplayText property.
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 + '-';
}
}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 SubUsing the 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 the needed cells.
void gridControl1_DrawCellDisplayText(object sender, GridDrawCellDisplayTextEventArgs e)
{
e.Style.RightToLeft = System.Windows.Forms.RightToLeft.No;
}Private Sub gridControl1_DrawCellDisplayText(ByVal sender As Object, ByVal e As GridDrawCellDisplayTextEventArgs)
e.Style.RightToLeft = System.Windows.Forms.RightToLeft.No;
End SubThe Screenshot displays the negative symbol in starting of the cell value in RTL mode.
Samples: