Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format datagridview column but avoid CellFormatting event

Status
Not open for further replies.

igor22

Programmer
Sep 18, 2003
50
US
Hi,
I need to display three numeric columns in datagridview so that all the numbers will show 2 digits after the decimal and if the number is negative it will appear in parentheses and in red font.
Right now I am doing that using CellFormatting event of my datagridview but it greatly effects the performance (binding and sorting) when I displaying more then a thousands records.

If sender.Columns(e.ColumnIndex).Name = "BeginQTY" Then
If e.Value IsNot Nothing Then
If CType(e.Value, Double) < 0 Then
e.Value = FormatNumber(e.Value, , , TriState.True)
e.CellStyle.ForeColor = Color.Red
e.CellStyle.SelectionForeColor = Color.Red
End If
End If
End If

Is there any other way to do it? Like create a custom column template or a custom column? I wasn't able to find any working code to solve my problem,

Thanks,

Igor
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top