bmt22033
bmt22033

Reputation: 7240

Fastest way to access cell value in bound DataGridView

I have a DataGridView that is bound to a BindingList of objects and I need to access the value of a particular cell in each row as quickly as possible. Is it faster to do:

if (((ObjectType)row.DataBoundItem).StringProperty != string.Empty)
{
}

...or...

if (row.Cells["STRINGPROPERTY"].Value != string.Empty)
{
}

Or is there another way that's faster than both of these?

Upvotes: 0

Views: 419

Answers (1)

spajce
spajce

Reputation: 7082

There's a lot of way to check the value with if is empty or null but from your main question you can go and try to Benchmarking method calls in C#

  1. String.IsNullOrEmpty
  2. String.IsNullOrWhiteSpace
  3. Best way to check if column returns a null value (from database to .net application)

Upvotes: 1

Related Questions