I wonder I cannot find a way to do it... I think this should be a very common task.
What I need - a kind of calculated columns. A user enters values in a row of datagrid. I want some cells to be calculated automatically, based on already entered columns. Ideally - in some cases - this automatically calculated columns may be overwritten by user, so it's a kind of default values. But defaults that are calculated on other columns, not constants!
If I try to use "expressions" on binded DataTable, there are two problems. 1st, this functionality is VERY limited, the "expression language" is able to calculate arothmetic sum but hardly anything more complex. I couldn'd find a way of using a custom, written in C#, function in these "expressions". But the real problem is that these calculated values are calculated and placed in grid only AFTER a user leave a row, while still editing a row a user cannot set these calculated values.
I tried to CurrentColumnChanged even (or something like that). Yes, I can get a DataGridColumnTextBox, as shown in one of MS examples. Yes, I can change the background color of this cell, as written in the same example. But I cannot change the Text of this TextBox! I assign a new value to Text, a debugger shows this new value OK, but I never see this new value in a grid or in binded datasource.....
Can anyone help me I think I demand just a reasonable behaviour of my grid.....

How to set values in grid cells programmatically?
B. Travis Wright
Dim CM as currencymanager = ctype(me.bindingcontext(dataset,"datatablename"),currencymanager)
Dim DRV as datarowview = ctype(cm.current,datarowview)
Drv.Item("ColumnName") = "value"
This is how it's done.
Don't bother trying to edit the actural values as they are in the datagrid programaticly, it's hell.
Ken Courts
Although I don't understand a thing about this binding context... what is it, how to use it... Reading MS documentaion seems to help little...
In my case this is the code that finally worked:
DataGrid thisGrid = (DataGrid) sender;
BindingManagerBase bm = BindingContext[thisGrid.DataSource, thisGrid.DataMember];
DataRowView drv = (DataRowView) bm.Current;
drv["columnname"]="value";
Your code
CurrencyManager=(CurrencyManager)this.BindingContext(....)
didn't want to returm (CurrencyManager) , but something called PropertyManager
I think I couldn't feed it the right paramters - and the right parameters are in the example above (still don't understand what it's all about :-)
Melchior91598
For example when you bind a datagrid, it creates a currencymanager, every object boud the same way will share the same currencymanager.
Using the currencymanager you can also navigate a datatable BTW.
Think of it as a object that keeps tabs on things and directs things.