Click here to Skip to main content
Rate this: bad
good
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 22:50pm
Comments
Tadit Dash at 29-Nov-13 5:11am
   
Debug and see on which line it is throwing the exception.
Rate this: bad
good
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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi
 
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
 
productkin.ToString(); 
 
use
  Convert.ToString(productkin);
  Permalink  

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 6,745
1 OriginalGriff 6,696
2 CPallini 5,315
3 George Jonsson 3,599
4 Gihan Liyanage 2,650


Advertise | Privacy | Mobile
Web04 | 2.8.140922.1 | Last Updated 29 Nov 2013
Copyright © CodeProject, 1999-2014
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