Click here to Skip to main content
15,903,385 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Am trying to get focused row cell value and previous row cell value of focused row. I used this code

C#
object eachprice = gridView1.GetRowCellValue(gridView1.FocusedRowHandle,gridView1.Columns["Price"])


this code get the value of price in focused row

C#
object eachprice = gridView1.GetRowCellValue(gridView1.FocusedRowHandle-1, gridView1.Columns["Price"]);


but this code didn't get the cell value of previous row. it show null value so i get error "Object reference not set to instance of Object"

this is my code

C#
private void discountcol()
    {

        if ((getdisc == tempstr) && (rownumber >= 1))
        {
            int focusedcount = gridView1.FocusedRowHandle;

            t1.Text = "";
            t1.Text = getdisc;

            object eachprice = gridView1.GetRowCellValue(focusedcount-1, gridView1.Columns["Price"]);
            t2.Text = eachprice.ToString();

            if (!(t2.Text == string.Empty))
            {
                decimal pricedecimal = Convert.ToDecimal(t2.Text);
                object eachdiscount = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns["Price"]);
                decimal eachdisdecimal = Convert.ToDecimal(eachdiscount);
                decimal tempdiscountprice = -(pricedecimal * (eachdisdecimal / 100));  // -ve calculation
                t3.Text = tempdiscountprice.ToString("N2");

                gridView1.SetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns["Price"], t3.Text);

                if (getdisc == tempstr)
                {
                    PricQuan.UnboundType = DevExpress.Data.UnboundColumnType.Decimal;
                    PricQuan.UnboundExpression = " 1 * [Price]";

                    TaxinAmount.UnboundType = DevExpress.Data.UnboundColumnType.Decimal;
                    TaxinAmount.UnboundExpression = " ([Price] * ([TaxInPercentage] / 100.0)) * 1 ";
                }
                else
                {
                    //PricQuan.UnboundType = DevExpress.Data.UnboundColumnType.Decimal;
                    //PricQuan.UnboundExpression = " Round([Quantity] * [Price], 2)";

                    //TaxinAmount.UnboundType = DevExpress.Data.UnboundColumnType.Decimal;
                    //TaxinAmount.UnboundExpression = " ([Price] * ([TaxInPercentage] / 100.0)) * [Quantity] ";
                }

            }

        }
        else
        {

        }
    }
Posted

1 solution

You can try using this code
C#
object Value = MyGridView.GetRowCellValue("ColumnName", MyGridView.FocusedRowHandle - 1);

For further details refer here,
http://documentation.devexpress.com/#windowsforms/DevExpressXtraGridViewsGridGridView_GetRowCellValuetopic[^]
 
Share this answer
 
Comments
srihari1904 30-Nov-13 2:39am    
@Thomas when i edit that code i got error like this "The best overloaded method matches found... has invalid arguments"

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