Can I, and should I, force the contents of DGV cells to be null?

I'm saving values entered in a DGV to a List<T>; they are decimal values or nothing (empty). If empty, I want them to be viewed as null, so that my helper function will see those empty vals as 0. But this line here:

rrsr.DuckbillRate = Convert.ToDecimal(GetValAtColRow(colNumber, rowNumber));

...sometimes fails with "Input string not in a correct format" (when it fails, the value it's trying to convert is a string.empty):

Here are my helper functions to get the cell values, so that I can save them in my List<T>, and restore/repopulate the cells from the contents of those records stored in the List<T>:

private string GetValAtColRow(int colNum, int rowNum)
{
 DataGridViewRow desiredRow = dataGridViewPlatypi.Rows[rowNum];
 return (desiredRow.Cells[colNum].Value ?? 0).ToString(); 
}

private void SetValAtColRow(int colNum, int rowNum, string val)
{
 string convertedVal = val;
 // If the value is 0, I want to display an empty cell (nothing)
 if (convertedVal.Equals("0"))
 {
  convertedVal = string.Empty;
 }
 DataGridViewRow desiredRow = dataGridViewPlatypi.Rows[rowNum];
 desiredRow.Cells[colNum].Value = convertedVal;
}

Answers


parsing is becoming wrong somewhere...

Input string not in a correct format error usually comes when parsing is not done correctly...

Regarding other issue...try to do like this>>>

string a =  dataGridViewPlatypi.Rows[rowNum].Cells[colNum].Value.toString()

if(a=="")
{
.
.
//further things
}

Need Your Help

How to order data received from SPHINX when using Yii Criteria?

php sql yii sphinx criteria

As SPHINX returns a list of id's, i cant see how to order my final results by using a criteria.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.