0

Am trying to get a cell value from gridview in repositoryItemGridLookUpEdit1_EditValueChanged event. But am getting null value only then error show like this "Object reference not set to an instance of an object" in that line.

How to get cell value in particular row from gridview in EditValueChanged Event ?

my code is this

 private void repositoryItemGridLookUpEdit1_EditValueChanged(object sender, EventArgs e)
    {
        GridLookUpEdit LookupEdit = sender as GridLookUpEdit;
        DataRowView SelectedDataRow = (DataRowView)LookupEdit.GetSelectedDataRow();



        gridView1.SetFocusedRowCellValue("Description", SelectedDataRow["ProductDescription"]);
        gridView1.SetFocusedRowCellValue("UoM", SelectedDataRow["UnitofMeasure"]);
        gridView1.SetFocusedRowCellValue("Quantity", SelectedDataRow["DefaultQuantity"]);
        gridView1.SetFocusedRowCellValue("Price", SelectedDataRow["MRPPrice"]);
        gridView1.SetFocusedRowCellValue("TaxInPercentage", SelectedDataRow["Taxid1"]);
        gridView1.SetFocusedRowCellValue("ProductKind", SelectedDataRow["ProductKind"]);

        getdisc = LookupEdit.EditValue.ToString(); // get display value & pass to comparision to find Discound

        object productkin = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns["ProductDescrption"]);

        string productkind = productkin.ToString(); // Error Object reference not set to instance of object

        MessageBox.Show(productkind, "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }

Help me ?

5
  • 2
    Which line you got that error?Maybe there're typo in the column names (They're case sensitive) Commented Nov 29, 2013 at 9:51
  • 1
    @User2012384 - indeed. ProductDescription versus ProductDescrption (note the missing i in the second one). Commented Nov 29, 2013 at 9:55
  • if (LookupEdit == null) return; after "as" Commented Nov 29, 2013 at 10:02
  • possible duplicate of What is a NullReferenceException and how do I fix it? Commented Nov 29, 2013 at 10:08
  • Hi User2012384 & Corak, Ya thanks now i solved that. I get value but I want to store the access db value to Unbound Column n Get that value. I hide that Unbound Column it is possible to get that value ? Commented Nov 29, 2013 at 10:11

1 Answer 1

2

As Corak noticed : you've got a typo error (missing "i") when getting the row cell value :

object productkin = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns["ProductDescrption"]);

As column "ProductDescrption" doesn't exist, the variable productkind is null. Replace this line with the following :

object productkin = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns["ProductDescription"]);
Sign up to request clarification or add additional context in comments.

1 Comment

Hi, ya i solved that. Is it possible to set SelectedDataRow["Value"] to Unbount Column and i need to get that cell value ??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.