It's possible in different ways. The easiest, probably would be using DataTable
having 3 columns, a, b and c, which c is an expression column having a+b as expression.
Another option, is using RowPrePaint
event of DataGridView
. (You can also use some other events like CellFormatting
.)
Example - Expression Column
var dt = new DataTable();
dt.Columns.Add("A", typeof(int));
dt.Columns.Add("B", typeof(string));
dt.Columns.Add("C", typeof(string), "CONVERT(A, System.String) + B");
dt.Rows.Add(1, "One");
dt.Rows.Add(2, "Two");
dataGridView1.DataSource = dt;
Example - RowPrePaint
dataGridView1.Columns.Add("A", "A");
dataGridView1.Columns.Add("B", "B");
dataGridView1.Columns.Add("C", "C");
dataGridView1.Rows.Add(1, "One");
dataGridView1.Rows.Add(2, "Two");
dataGridView1.RowPrePaint += (s, a) =>
{
if (a.RowIndex >= 0)
{
var g = (DataGridView)s;
g["C", a.RowIndex].Value = $"{g["A", a.RowIndex].Value}{g["B", a.RowIndex].Value}";
}
};