发生mscorlib.dll错误时发生未处理的“System.StackOverflowException”类型异常?

时间:2013-11-25 13:51:27

标签: c# .net winforms gridview devexpress

收到错误未绑定表达式。我创建了一个新专栏&运行时无界表达式。我从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
        {
            }
    }

帮帮我,我想得到&设定值

1 个答案:

答案 0 :(得分:2)

你的堆栈跟踪的最后几帧可能很有用......即使有了所有这些代码,我们也只能推测。

但我同意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?请参阅this,了解调用此事件时给您的内容。

edit2:为什么要使用自定义机制,如果您只想将两列相乘? unbColumn.UnboundExpression = "[Quantity] * [Each]";就足够了,不是吗?