Jump to content


  • Please log in to reply
2 replies to this topic

#1 Kalint


    Neowinian Senior

  • Tech Issues Solved: 2
  • Joined: 16-January 07

Posted 15 March 2013 - 19:47

The concept is simple. The user selects a row and clicks "Edit", opens the form and all the data from the row is in the perspective fields on the edit form.

I've had no problem doing this method with a ListView using SelectedItems[0].Tag, but working with a DataGridView now and I get a object reference error.

How doe I get the values of the cells to populate "part"?

The datagridview is in full row select, multiselect false.

private void EditPart()
		    PartData part;
		    // Ignore if no row is selected
		    if (DgParts.SelectedRows.Count == 0)
			    // Is not tagging data at all.
			    part = (PartData)DgParts.SelectedRows[0].Tag;
			    // Open Form with Data
			    var edit = new FrmPartsAddEdit(this, "Edit", part);
			    // Commit if OK
			    if (edit.ShowDialog() == DialogResult.OK)
				    part = edit.GetPart();
                    // DB Stuff


#2 PeteDaCoder



  • Joined: 14-March 13

Posted 16 March 2013 - 07:28


Do you have the remaining code to see how your populating the DataGridView? Also which row is throwing the object not referenced error?


#3 Kami-


    ♫ d(-_-)b ♫

  • Tech Issues Solved: 3
  • Joined: 28-July 08
  • Location: SandBox

Posted 18 March 2013 - 12:36

part = (PartData)DgParts.SelectedRows[0].Tag;
Doesn't look right to me...