Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#5.0

EditedFormattedValue v/s Value in Datagridview

4.71/5 (3 votes)
24 May 2014CPOL 23.1K  
There is usually a mis-conception with people thinking DataGridView Cell.Value gets the current value of the cell in datagridview. This article will tell you the difference between EditedFormattedValue v/s Value in Datagridview.

Introduction

This tip will help developers to understand how to retrieve current exact value from datagridview cell.

DataGridViewCell.Value Property

"DataGridViewCell.Value" or "Value" 's function is to get or set the value of the associated cell but there is a problem with the Property "Value" viz., every time you leave the cell, formatting is needed to display the content on the user interface. While you use "Value", sometimes it does not format the content of the cell and when you try to retrieve the data like this:

C#
string str = datagridview1.Rows[0].Cells[0].Value.ToString();  

Output

You might get some previously written data or null value.

DataGridViewCell.EditedFormattedValue Property

"DataGridViewCell.EditedFormattedValue" Or "EditedFormattedValue" 's function is to get the current, formatted value of the cell, regardless of whether the cell is in the edit mode and the value has not been committed. EditedFormattedValue ensures that the value is committed or saved at every point of coding. You can use the property like this:

C#
string str = dataGridView1.Rows[0].Cells[0].EditedFormattedValue.ToString();

Output

This will give you the current exact value of the dataGridView's cell.

License

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