Click here to Skip to main content
13,046,337 members (68,904 online)
Rate this:
Please Sign up or sign in to vote.
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 ?
Posted 28-Nov-13 22:50pm
Tadit Dash 29-Nov-13 5:11am
Debug and see on which line it is throwing the exception.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

So check in the debugger and look at the line:
object productkin = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns["ProductDescrption"]);
Look at the FocusedRowHandle, and gridView1.Columns["ProductDescrption"] and see what cell they are trying to return.

We can't - we don't have access to your data.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


this the common error while handling reference type object

Please make sure that the object is not null , before accessing its members , methods..

try this..

instead of



This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 29 Nov 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100