Home > Net >  Whether DatagGridiView cell to an empty string or null
Whether DatagGridiView cell to an empty string or null

Time:11-01

The following code, I want to determine whether a DatagGridiView winform in cell to an empty string or null, if not all together as they are,
The following 5 lines of code is too hurt, is there anyone more elegant writing?

 var vendors=string. The Empty; 
Foreach (DataGridViewRow row in DGV. Rows)
{
Object vendor=row. Cells [r]. "colVendor" Value;
If (vendor!=null & amp; & Vendor. The ToString ()!=string. The Empty & amp; & ! Vendors. The Contains (vendor. The ToString ()))
{
Vendors +=vendor. The ToString () + "; ";
}
}

CodePudding user response:

This judgment
if (! String. IsNullOrEmpty (vendor))
{


}

CodePudding user response:

Thanks for your reply, but compiling pass, vendor is object type

CodePudding user response:

The inside in. Tostring

CodePudding user response:

reference 1st floor ManBOyyy response:
like this judgment
if (! String. IsNullOrEmpty (vendor))
{


}

Then you can turn the string:
 if (! String. IsNullOrEmpty (vendor. The ToString ())) 
{


}

CodePudding user response:

refer to the second floor leon51 response:
thank you for your reply, but compiling pass, vendor is object of type


Provides parameters to declare the actual type, such as
 (string) vendor 

CodePudding user response:

C # does not like js is a wonky language environment, the c # compiler help programmers check ahead of a large number of programming errors, so is a strongly typed language, so to write
 if (! String. IsNullOrEmpty ((string) vendor)) 
convince the compiler that you "own type of exception handling",
  •  Tags:  
  • C#
  • Related