c1 truedbgrid make third column auto compute by the values of two column

612 Views Asked by At

Code for dataset:

DataSet ds = new DataSet();

DataTable dt = new DataTable();
dt.Columns.Add("DENOMINATION");
dt.Columns.Add("COUNT");
dt.Columns.Add("TOTAL");

dt.Rows.Add(new object[] { "1000", "0", "0" });
dt.Rows.Add(new object[] { "500", "0", "0" });
dt.Rows.Add(new object[] { "200", "0", "0" });
dt.Rows.Add(new object[] { "100", "0", "0" });
dt.Rows.Add(new object[] { "50", "0", "0" });
dt.Rows.Add(new object[] { "20", "0", "0" });
dt.Rows.Add(new object[] { "10", "0", "0" });
dt.Rows.Add(new object[] { "5", "0", "0" });
dt.Rows.Add(new object[] { "1", "0", "0" });
dt.Rows.Add(new object[] { "0.25", "0", "0" });
dt.Rows.Add(new object[] { "0.10", "0", "0" });
dt.Rows.Add(new object[] { "0.05", "0", "0" });

ds.Tables.Add(dt);

dgDENOM.AllowUpdate = true;
dgDENOM.SetDataBinding(dt, "", true);

In UI:

DENOMINATION    COUNT     TOTAL
1000            0         0
500             0         0

What I want in real time/runtime, the column count will be modified and after that the value of total = denomination * count. I will put it on a event of the db grid.

Sample output

DENOMINATION    COUNT     TOTAL
1000            5         5000
500             4         2000
1

There are 1 best solutions below

0
Zohar Peled On

In c1TrueDbGrid you can have an unbound column.
You populate that column using the C1TrueDBGrid.UnboundColumnFetch event.

The UnboundColumnFetchEventArgs class contains readonly properties for the grid row, column, and column index, and a read/write property for value.

Use the Value property to set the cell value for each row - something like this (untested):

private void c1TrueDBGrid1_UnboundColumnFetch(object sender, UnboundColumnFetchEventArgs e)
{
    var row = e.Row;
    var denomination = (int)grid.Columns["DENOMINATION"].CellValue(row);
    var count = (int)grid.Columns["COUNT"].CellValue(row);
    e.value = denomination * count;
}