Click here to Skip to main content
11,479,034 members (62,646 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# Gridview DevExpress
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 23:50pm
Tadit Dash at 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
0 Sergey Alexandrovich Kryukov 200
1 F-ES Sitecore 195
2 Frankie-C 120
3 OriginalGriff 105
4 DamithSL 95
0 Sergey Alexandrovich Kryukov 7,880
1 OriginalGriff 7,341
2 Sascha Lefèvre 3,064
3 Maciej Los 2,491
4 Richard Deeming 2,335

Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 29 Nov 2013
Copyright © CodeProject, 1999-2015
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