Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
C#
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
Comments
Debug and see on which line it is throwing the exception.

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

C#
productkin.ToString(); 


use
C#
Convert.ToString(productkin);
 
Share this answer
 
So check in the debugger and look at the line:
C#
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900