Click here to Skip to main content
15,885,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

i try to set row cell value but this error appear at this line
//select deafult store
                gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "storeID", BasicVars.DeafulStore);


MessageBox appeared an it say : Object reference set to an instance of an object
but there is no any other details:

the full code
private void AddNewRowWithChossedFromSearchLookUpEdit(int CHK_itemID)
{
    if (CHK_itemID == 0) return;
    mrsalesdbEntities DB01 = ConnectionTools.OpenConn();
    var ItemData = DB01.st_items.Find(CHK_itemID);


    //items
    // gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "stitems_ID", SearchBarcode_ItemID_result);
    // searchedSerial = sForm.SearchValue;
    gridView1.AddNewRow();
    int rowHandle = gridView1.FocusedRowHandle;
    decimal taxPercent = 0;
    try
    {
        if (ItemData.stitems_HaveTax == 1)
        {
            taxPercent = ItemData.stitems_TaxValue.Value;
        }
        else { taxPercent = 0; }
    }
    catch
    {
        taxPercent = 0;
    }
    gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "taxp", taxPercent);


        //select deafult store
        gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "storeID", BasicVars.DeafulStore);

        //select Smallest Unit
        var DB02 = ConnectionTools.OpenConn();
    var UnitItemData = LoadedUnits.Where(u => u.stitems_ID == CHK_itemID).OrderBy(o => o.stitemsu_UnitNum).FirstOrDefault();
    gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "unit_ID", UnitItemData.stitemsu_ID);

    //qnty = 1
    gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "sitem_Quantity", 1);
    // call function to Get the selected unit details ( price , discount , bounce)
    if (gridView1.GetFocusedRowCellValue("stitems_ID") != null || gridView1.GetFocusedRowCellValue("unit_ID") != null ||
           gridView1.GetFocusedRowCellValue("sitem_Quantity") != null)
    {
        int UnitID = Convert.ToInt32(gridView1.GetFocusedRowCellValue("unit_ID"));
        GetUnitDetails(UnitID);
        GetBounce(UnitID);
    }

    int StoreID = Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "storeID"));
    int itemID = CHK_itemID;
    try
    {

        //get all avaliable Expired Date
        ExpiredDateCombo.Items.Clear();
        if (ItemData.stitems_Type.Value == 0)
        {
            var DB0201 = ConnectionTools.OpenConn();
            var EXdates = DB0201.stock_noserials.Where(u => u.stitems_ID == CHK_itemID && u.StoreID == StoreID && u.StockQnty > 0).OrderBy(o => o.ExpireDate).ToList();
            foreach (var d in EXdates)
            {
                ExpiredDateCombo.Items.Add(d.ExpireDate.Value.ToString("yyyy-MM-dd"));
            }
            gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "ExpiredDate", EXdates.FirstOrDefault().ExpireDate.Value.ToString("yyyy-MM-dd"));
            gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "BatchNum", EXdates.FirstOrDefault().BatchNum.ToString());

        }
        else if (ItemData.stitems_Type.Value == 1)
        {
            var DB0201 = ConnectionTools.OpenConn();
            var EXdates = DB0201.purchases_item_seriels.Where(u => (u.stitems_ID == CHK_itemID && u.ss_StoreID == StoreID && u.pis_Statues == 0) ||
                                                                    (u.stitems_ID == CHK_itemID && u.ss_StoreID == StoreID && u.pis_Statues == 5) ||
                                                                    (u.stitems_ID == CHK_itemID && u.ss_StoreID == StoreID && u.pis_Statues == 6)).OrderBy(o => o.pis_ExpireDate).ToList();
            foreach (var d in EXdates)
            {
                ExpiredDateCombo.Items.Add(d.pis_ExpireDate.Value.ToString("yyyy-MM-dd"));
            }
            gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "ExpiredDate", EXdates.FirstOrDefault().pis_ExpireDate.Value.ToString("yyyy-MM-dd"));
            gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "BatchNum", EXdates.FirstOrDefault().BatchNum.ToString());
        }
    }
    catch {

    }
    // Validate all row cells
    gridView1.ClearColumnErrors();
    PathingVars.RowValid = 1;
    ClearValidationsErrs = 0;

    gridView1.PostEditor();
    gridView1.UpdateCurrentRow();
    gridView1.FocusedRowHandle = gridView1.DataRowCount - 1;
    gridView1.FocusedColumn = gridView1.Columns["sitem_NetPrice"];

}


What I have tried:

i tried to write this line between try and catch to see the error details but no msg. appeared

try
{

    //select deafult store
    gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "storeID", BasicVars.DeafulStore);
}
catch (Exception exxxxx) { MessageBox.Show(exxxxx.ToString()); }


please note that the "storeID" is a column in gridView1 and , BasicVars.DeafulStore have value "1" and not null.
Posted
Updated 21-Feb-20 11:48am
v4
Comments
ZurdoDev 21-Feb-20 16:04pm    
It is very simple to fix and only you can do it because we cannot run your code. First identify the specific line of code that is throwing the error then put a breakpoint on it and examine what is null.

Simple.
Golden Basim 21-Feb-20 16:13pm    
i did that , the line
gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "storeID", BasicVars.DeafulStore);
and there is no any null object
ZurdoDev 21-Feb-20 16:25pm    
Something is or else you would not get that error.

What is the value of gridView1.FocusedRowHandle?
And what is BasicVars.DeafulStore?
And are you sure there is a field with the name "storeID". It might be case sensitive.
Golden Basim 21-Feb-20 16:33pm    
gridView1.FocusedRowHandle = 0 , BasicVars.DeafulStore = 1 ,storeID is a correct.
ZurdoDev 21-Feb-20 16:37pm    
Are you sure that line is what is throwing the error?

The only reliable way to solve the problem is to place a breakpoint to the method and use the debugger to find out what is happening and what are the values of each variable.

If not gone through the basic operations, have a look at First look at the debugger - Visual Studio | Microsoft Docs[^]

One very good tool is the QuickWatch window: Watch and QuickWatch Windows - Visual Studio 2015 | Microsoft Docs[^]

You can place the whole problem statement into the QuickWatch and you'll see if an exception is thrown. Also, you can modify the statement to see what is null and what modifications help in the problem.
 
Share this answer
 
thanks , i found the the solution ..

by setting gridview cell value using gridView1.SetRowCellValue it raise others events such as gridView1_CellValueChanged and gridView1_ValidateRow and others. i checked every event and i get the null variable.

thanks
 
Share this answer
 
v2

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