Click here to Skip to main content
15,891,033 members
Articles / Programming Languages / C# 5.0
Tip/Trick

EditedFormattedValue v/s Value in Datagridview

Rate me:
Please Sign up or sign in to vote.
4.71/5 (3 votes)
24 May 2014CPOL 22.5K   2   2
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)


Written By
Software Developer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
SuggestionClarification on EditedFormattedValue Pin
Emily Heiner26-May-14 12:39
Emily Heiner26-May-14 12:39 
GeneralRe: Clarification on EditedFormattedValue Pin
agent_kruger26-May-14 19:42
professionalagent_kruger26-May-14 19:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.