Reputation: 12012
Using VB.Net
I want to make a datagird cell value zero instead of null
For example
Datagridview1
Id value1 value2 value3
01 null null 0
02 0 null 10
03 100 null 100
...
Expected output
Id value1 value2 value3
01 0 0 0
02 0 0 10
03 100 0 100
...
I have more than 80 columns and 100 rows, instead of checking the cell one by one any other method is available
Tried Code
Private Sub dataGridView1_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs)
If e.ColumnIndex = 0 AndAlso e.Value IsNot Nothing Then
If CInt(e.Value) = 0 Then
e.Value = ""
End If
End If
End Sub
The above code is not working properly, when i add the details in datagridview from database, showing null cell also.
How to make zero instead of null. Any other method or suggestion
Need VB.Net code help
Upvotes: 0
Views: 4362
Reputation: 26396
You can also set it from code
dataGridView1.DefaultCellStyle.NullValue = 0;
Gets or sets the System.Windows.Forms.DataGridView cell display value corresponding to a cell value of System.DBNull.Value or null.
Upvotes: 6