locked
error message "object reference not set to an instance of an object"

    Question

  • I'm currently developing an application with C # and sql server 2005,
    in a stage of my program, I used datagridview whose first column is type DataGridViewCheckBoxColumn, I managed to recover the value of this column in my tableSQL, and my program works very well, but every time that I open my window it gives me the error message
     "object reference not set to an instance of an object"

    Note:
    I wrote my program in the event cellvaluechage, but I do not know is this-it's a problem event, because when I tried to write in another event (CellClick), it I have not posted this error message, but the program does not work, I do not recover the value of checkbox
    do-someone to help me and tell me what the error message.
    thank you very much.

    Wednesday, December 01, 2010 8:01 AM

Answers

  • hi, haf.

    That means you got a null data.

    i advise you to debug the program, and you will get the null data.

    if the datagridview was bind, you could not change the cell value.

     thanks!

    • Proposed as answer by Wenjie Li Friday, December 03, 2010 6:11 AM
    • Marked as answer by Bin-ze Zhao Wednesday, December 08, 2010 6:49 AM
    Wednesday, December 01, 2010 10:03 AM

All replies

  • try with DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; in the form load or in form designer page and make sure to use cellvaluechanged event.

     


    Thanks, Srinivasa Rao Dhulipalla
    Mark As Answer if it helped you.
    Wednesday, December 01, 2010 8:49 AM
  • hi, haf.

    That means you got a null data.

    i advise you to debug the program, and you will get the null data.

    if the datagridview was bind, you could not change the cell value.

     thanks!

    • Proposed as answer by Wenjie Li Friday, December 03, 2010 6:11 AM
    • Marked as answer by Bin-ze Zhao Wednesday, December 08, 2010 6:49 AM
    Wednesday, December 01, 2010 10:03 AM
  • Examine the variables on the line where the exception occurs. One of them is null.

    Wednesday, December 01, 2010 10:04 AM
  • hi, Wen.

    thanks thanks

    I checked everything and you're right, I had a problem with null
    My datagridview is null when loading the window. that's why he has not found anything back.

    I solved the problem.

    thanks

    Wednesday, December 01, 2010 10:38 AM
  • thanks thanks

    I checked everything and you're right, I had a problem with null
    My datagridview is null when loading the window. that's why he has not found anything back.

    thanks

    Wednesday, December 01, 2010 10:39 AM
  • hello.
    finally I had a problem with null, my datagridview is null on loading from my window.
    so I solved the problem with an If condition
    thank you very much.
    Wednesday, December 01, 2010 10:47 AM
  • hi, Wen.

    thanks thanks

    I checked everything and you're right, I had a problem with null
    My datagridview is null when loading the window. that's why he has not found anything back.

    I solved the problem.

    thanks


    well done!
    Thursday, December 02, 2010 1:50 AM