Click here to Skip to main content
Click here to Skip to main content
Go to top

EditedFormattedValue v/s Value in Datagridview

, 24 May 2014
Rate this:
Please Sign up or sign in to vote.
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:

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:

 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)

Share

About the Author

Agent_Spock
Software Developer
India India
No Biography provided

Comments and Discussions

 
SuggestionClarification on EditedFormattedValue PinmemberMember 215083926-May-14 12:39 
GeneralRe: Clarification on EditedFormattedValue PinprofessionalAgent_Spock26-May-14 19:42 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 24 May 2014
Article Copyright 2014 by Agent_Spock
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid