0

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

5
  • 1
    My guess is that it is your call to gridView1.SetRowCellValue that causes gridView1_CustomUnboundColumnData event to be called Commented Nov 25, 2013 at 13:56
  • Hi Jens, If i modify SetRowCellValue to gridView1_CustomUnboundColumnData it shows error like "The CustomUnboundColumnData event can only appears left hand side of += or =+ " Commented Nov 25, 2013 at 14:03
  • yes ofc :D hehe, why would you do that? instead of using gridView1... try and see if the e variable can be used instead.. Commented Nov 25, 2013 at 14:13
  • Hi Jens, :D Am new to c# that's why.... No e. is not working there because it is outside that function so. Commented Nov 25, 2013 at 14:29
  • Sure, "e" is outside of "calfun"... but you must pass it as an argument, or move your code in the event handler. Your "calfunc" as it is not clean. Commented Nov 25, 2013 at 15:24

1 Answer 1

2

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 ?

Sign up to request clarification or add additional context in comments.

2 Comments

I completly agree - I would think that unbColumn.UnboundExpression = "[Quantity] * [Each] is sifficient
Hi Jens & Olivier, My task is to obtain "discount on previous item" in Gridview, so I need to get a cell value on previous row & get the cell value in current row, so I used (FocusedRowHandle). Then I want to multiply both values and obtain new value. Finally that new value is want to stored in Unbound Column[PriceQuantity]. This are all done when i select 'Discount' in the RepositoryLookupEdit in the Bound Column. If I select any other Item from RepositoryLookupEdit then 'Discount' I need to calculate Unbound Expression[Quantity]*[Each]. Help me to complete my task ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.