簡體   English   中英

發生mscorlib.dll錯誤時發生未處理的“System.StackOverflowException”類型異常?

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

我收到錯誤Unbound Expression。 我在運行時創建了一個新列和Unbounded Expression。 我從gridview獲取特定的單元格值(GetRowCellValue)並嘗試使用新值(SetRowCellValue)更改該未綁定的表達式列。 但錯誤顯示我的錯誤? 幫我。

這是我的代碼。

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]";

    }

獲取價值和設定價值的代碼

 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
        {
            }
    }

幫助我請我想獲得並設定價值

堆棧跟蹤的最后幾幀可能很有用......即使使用了所有這些代碼,我們也只能推測。

但我同意JensKloster的評論:DevExpress未綁定列用於顯示未綁定列(然后從其他列計算)。

此事件可讓您計算此值。 每次更改行中的某些內容時都會調用它。 因此,從中調用setvalue將導致該方法自己調用它。 (=>堆棧溢出異常)

使用e.Value = myValue設置您的值:

e.Value = c;

代替

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

其中e是作為事件參數給出的DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs。

編輯:另外,我想,當使用gridView1.FocusedRowHandle ,你指的e.RowHandle 看到這個 ,看看調用此事件時給你的是什么。

edit2:為什么要使用自定義機制,如果你只想乘以兩列? unbColumn.UnboundExpression = "[Quantity] * [Each]"; 已經足夠了,不是嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM