Click here to Skip to main content
15,066,496 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to allow null values in datagridview cells?
i have 3 column is there...
i entered 1st column--->1st cell value then enter error will came
that means 2column-->1st cell is null ah..... 2column -->1at cell null values dot allow for datagridview

how to allow null values in datagridview cell?
Updated 19-Sep-21 1:41am
lw@zi 20-Jan-16 23:36pm
More details needed. Are you doing data binding? DO NOT use comments for these details. USE IMPROVE QUESTION link to update your question.
Sergey Alexandrovich Kryukov 20-Jan-16 23:36pm
What is the cell type? Did you try to assign null to cell.Value?

private void dataGridView1_CellFormatting(object sender,
    DataGridViewCellFormattingEventArgs e)
    String value = e.Value as string;
    if ((value != null) && value.Equals(e.CellStyle.DataSourceNullValue))
        e.Value = e.CellStyle.NullValue;
        e.FormattingApplied = true;

please refer below link[^]
Below are steps to handle DataGridView cell Bill Exception program
#1. Create a string
#2. Pass the DataGridView current cell value into the string
#3. Then give the string a condition to be evaluated
#4. Then perform your intended action
String a = (DataGridView.CurrentCell.value).To string();
Now here is the condition to be evaluated
If(a != String.empty)
{Int cellValue = convert.toInt32(a)}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900