简体   繁体   中英

An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll error occurred?

Am getting error Unbound Expression. I Created a new column & Unbounded Expression on Runtime. I get a particular cell values(GetRowCellValue) from gridview and try to change that unbound expression column with new value(SetRowCellValue). But error shown whats my mistake ? Help me.

This is my Code.

private void unbound2_Load(object sender, EventArgs e)
    {
        // TODO: This line of code loads data into the 'orionSystemDataSet.Test_Product' table. You can move, or remove it, as needed.
        this.test_ProductTableAdapter.Fill(this.orionSystemDataSet.Test_Product);
        // TODO: This line of code loads data into the 'orionSystemDataSet.Test_Gridview' table. You can move, or remove it, as needed.
        this.test_GridviewTableAdapter.Fill(this.orionSystemDataSet.Test_Gridview);


        var product = repositoryItemGridLookUpEdit1.View.Columns.AddField("Type");
        product.Visible = true;


        //create unbound column in form load
        unboundcreate();

    }

    private void unboundcreate()
    {
        gridControl1.ForceInitialize();

        GridColumn unbColumn = gridView1.Columns.AddField("PriceQuantity");
        unbColumn.Caption = "PricQuan";
        unbColumn.VisibleIndex = gridView1.Columns.Count;
        unbColumn.UnboundType = DevExpress.Data.UnboundColumnType.Decimal;
        unbColumn.OptionsColumn.AllowEdit = false;
        unbColumn.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
        unbColumn.DisplayFormat.FormatString = "c";
        unbColumn.AppearanceCell.BackColor = Color.LemonChiffon;
        unbColumn.UnboundType = DevExpress.Data.UnboundColumnType.Decimal;
        unbColumn.UnboundExpression = "[Quantity] * [Each]";

    }

Code to get value & set value

 private void gridView1_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
    {

            GridView view = sender as GridView;


            if (e.Column.FieldName == "PriceQuantity" && e.IsGetData)
            {
                //e.Value = getTotalValue(view, e.ListSourceRowIndex);
                calfun();
            }
            else
            {
                // nothing
            }

    }


    private void calfun()
    {
        if (gridView1.FocusedRowHandle >= 1)
        {

            string temp = "Discount";
            //string dis = TXE_Gettype.Text.ToString();
            object objec = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns["Type"]);
            string dis = objec.ToString();

            if (dis == temp)
            {
                object obj = gridView1.GetRowCellValue(gridView1.FocusedRowHandle - 1, gridView1.Columns["Each"]);

                int aa = Convert.ToInt32(obj);
                //textEdit1.Text = aa.ToString();

                object obj1 = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns["Each"]);

                int a = Convert.ToInt32(obj1);
                int b = aa;

                int c = a * b;

                //textEdit2.Text = c.ToString();

                gridView1.SetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns["PriceQuantity"], c);
            }
        }
        else
        {
            }
    }

Help me Please I want to get & set value

The last couple of frames of your stacktrace could be usefull... even with all this code, we can only speculate.

But I agree with JensKloster's comment: DevExpress unbound columns are made to display unbound columns (computed, from others, then).

The event is here to make you compute this value. It is called each time you change something in your row. Thus, calling setvalue from it will cause the method to call it itself. (=> stack overflow exception)

Use e.Value = myValue to set your value:

e.Value = c;

instead of

gridView1.SetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns["PriceQuantity"], c);

where e is the DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs given as an argument of your event.

edit: Moreover, I guess that when using gridView1.FocusedRowHandle , you were refering to e.RowHandle ? See this to see what is given to you when this event is called.

edit2: why using custom mechanisms if you just want to multiply two columns ? unbColumn.UnboundExpression = "[Quantity] * [Each]"; is sufficient, isnt it ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM