Check whether an Object is empty or null
11,065
You can get the actual edited Value by using the .EditedFormattedValue
if (string.IsNullOrWhiteSpace(gvProductBatch.Rows[i].Cells["txtSellQty"].EditedFormattedValue.ToString())
{
//Do something
}
Author by
Prathap
Updated on June 04, 2022Comments
-
Prathap almost 2 years
I have a
DataGridView
and added a column calledSellQty
and aCheckbox
at index 0. User has to enterint
value when he selects acheckbox
. If not I am showing a message to enter the value. Now the problem is I am getting the value from theSellQty
cell and storing it in anobject
and checking whether it isnull
.object SellQty = gvProductBatch.Rows[i].Cells["txtSellQty"].Value; if(SellQty!=null) // do something else // ..Show message.
This works fine. But the problem is when the user enters a value and deletes it, the value stored in it is
{}
i.e. empty. I would like to know how to check an object is empty. I have googled for the same but didn't find answer to handle empty object. All results were for if object is null. -
Prathap about 11 yearsI am using 3.5.Anywaz I have used NullorEmpty and it works great.Thanks mate.Can you just explain a bit about this line of code.
-
spajce about 11 yearsheres the msdn reference will explain to you. welcome
:)
-
Prathap about 11 yearsGone through it.Thanks.I have changed the validation and calculations in my entire module.It works great. I didn't handle this exception when user enters a white space in whole module.Now it works great
-
spajce about 11 yearsyou use like this way.
if (gvProductBatch.Rows[i].Cells["txtSellQty"].EditedFormattedValue.ToString().Trim().Length == 0) { //Do something }