Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8567601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:55:12+00:00 2026-06-11T17:55:12+00:00

When refreshing my DGV contents (not data-bound, populated in code), I’ve got this code

  • 0

When refreshing my DGV contents (not data-bound, populated in code), I’ve got this code that retrieves the values in the cells:

DataGridViewRow desiredRow = dataGridViewPlatypi.Rows[rowNum];
return desiredRow.Cells[colNum].Value.ToString();

It works fine as long as there is a value in the cell; if the cell is empty, it fails with “Null reference exception | Object reference not set to an instance of an object” on the second line.

I can work around this my giving each cell a “0” or a ” ” (space), but I’d rather not do that. Is there a more elegant way of handling this (blank cell) condition?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:55:13+00:00Added an answer on June 11, 2026 at 5:55 pm

    You can use the null-coalescing operator to test for a null value in your cell and if the value is found to be null, return a string of your choice. Otherwise the cell’s string value is returned:

    DataGridViewRow desiredRow = dataGridViewPlatypi.Rows[rowNum];
    return (desiredRow.Cells[colNum].Value ?? "empty").ToString();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am refreshing openmp a bit, and got into this weird situation. Shaved off
IE 8 is not refreshing a popup window that shows an image with some
I have the following code in a class that manages refreshing some object automatically
I am using following code for a refreshing page, it is not reloading on
If you keep on refreshing https://ssl.google-analytics.com/ga.js you will notice that the contents keeps switching
Refreshing on floating points (also PDF ), IEEE-754 and taking part in this discussion
I have an excel file which is refreshing data every few seconds and running
I'm refreshing my C++ knowledge after not having used it in anger for a
What is the preferred method of refreshing a combo box when the data changes?
Update : success progress but still a problem : new data reloaded after refreshing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.