Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Read null value(s) from cell of DataGridView

Read null value(s) from cell of DataGridView

Scheduled Pinned Locked Moved C#
helptutorialquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    M Riaz Bashir
    wrote on last edited by
    #1

    Hi, kindly help me that, how to read null values from datagridview? Thanks in advance (Riaz)

    J 1 Reply Last reply
    0
    • M M Riaz Bashir

      Hi, kindly help me that, how to read null values from datagridview? Thanks in advance (Riaz)

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      You read it like any other value. E.g. object cellValue = dataGridView.Rows[0].Cells[0]; Doesn't matter whether it's null or not. Does this answer your question?

      M 1 Reply Last reply
      0
      • J Judah Gabriel Himango

        You read it like any other value. E.g. object cellValue = dataGridView.Rows[0].Cells[0]; Doesn't matter whether it's null or not. Does this answer your question?

        M Offline
        M Offline
        M Riaz Bashir
        wrote on last edited by
        #3

        i am facing an error "NullReferenceExeption was unhandled" using following codes. object oValueChecker = Convert.IsDBNull(dataGridView1[5, e.RowIndex].Value)? "0" : dataGridView1[5, e.RowIndex].Value.ToString().Trim(); if (oValueChecker == "0") { dataGridView1[5, e.RowIndex].Value = "0"; }

        K L 2 Replies Last reply
        0
        • M M Riaz Bashir

          i am facing an error "NullReferenceExeption was unhandled" using following codes. object oValueChecker = Convert.IsDBNull(dataGridView1[5, e.RowIndex].Value)? "0" : dataGridView1[5, e.RowIndex].Value.ToString().Trim(); if (oValueChecker == "0") { dataGridView1[5, e.RowIndex].Value = "0"; }

          K Offline
          K Offline
          Kjetil Svendsen
          wrote on last edited by
          #4

          Hi. Have you tried

          if (string.IsNullOrEmpty(dataGridView1[5, e.RowIndex].Value.ToString()))
          {
          dataGridView1[5, e.RowIndex].Value = "0";
          }

          I think it should work. Kjetil

          L 1 Reply Last reply
          0
          • M M Riaz Bashir

            i am facing an error "NullReferenceExeption was unhandled" using following codes. object oValueChecker = Convert.IsDBNull(dataGridView1[5, e.RowIndex].Value)? "0" : dataGridView1[5, e.RowIndex].Value.ToString().Trim(); if (oValueChecker == "0") { dataGridView1[5, e.RowIndex].Value = "0"; }

            L Offline
            L Offline
            leppie
            wrote on last edited by
            #5

            M Riaz Bashir wrote:

            Value.ToString()

            If Value is null, ToString() will FAIL!

            xacc.ide - now with TabsToSpaces support
            IronScheme - 1.0 alpha 4a out now (29 May 2008)

            1 Reply Last reply
            0
            • K Kjetil Svendsen

              Hi. Have you tried

              if (string.IsNullOrEmpty(dataGridView1[5, e.RowIndex].Value.ToString()))
              {
              dataGridView1[5, e.RowIndex].Value = "0";
              }

              I think it should work. Kjetil

              L Offline
              L Offline
              leppie
              wrote on last edited by
              #6

              Kjetil Svendsen wrote:

              string.IsNullOrEmpty(dataGridView1[5, e.RowIndex].Value.ToString())

              IF the Value property is null, you will still get a NullReferenceException.

              xacc.ide - now with TabsToSpaces support
              IronScheme - 1.0 alpha 4a out now (29 May 2008)

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups