• 0

C# DataGridView values giving error when trying to open a form.


Question

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)
{
return;
}
try
{
// 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
}
}
[/CODE]

Thaaaaaaanks!

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Hi,

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

Thanks

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.