Anybody does know about my problem. ???
Kamal,
I am new to C#, and cannot help with the lookup field, but I have added a
calculated field to my datagrid - it is not too difficult.
You need to manually define the DataGridTableStyle and set up the columns
using DataGridColumnStyle. The other advantage of this is you can define
alternate column headings and column widths as well.
Here is a section of my code that sets up the columns for one of my
datagrids... including a calculated column. The Expression is where you
perform the calculation (ie "Qty * Amount) - you simply use field names. In
my case I calculate a value from a child table.
DataGridTableStyle ts = new DataGridTableStyle();
DataGridColumnStyle csCustID = new DataGridTextBoxColumn();
DataGridColumnStyle csSurname = new DataGridTextBoxColumn();
DataGridColumnStyle csFirstName = new DataGridTextBoxColumn();
DataGridColumnStyle csAddress = new DataGridTextBoxColumn();
DataGridColumnStyle csLastServ = new DataGridTextBoxColumn();
private void setupCustomerColumns()
{
// Set the DataGridTableStyle.MappingName property
// to the table in the data source to map to.
ts.MappingName = dsCRSdata.Tables[0].TableName;
// Set up the header text and display length for each column
setupColumn(0, csCustID, 0,"ID", 20);
setupColumn(0, csSurname, 1,"", 100);
setupColumn(0, csFirstName, 2,"First Name", 100);
setupColumn(0, csAddress, 3, "",200);
dsCRSdata.Tables[0].Columns.Add("LastServiceDate", typeof(DateTime));
dsCRSdata.Tables[0].Columns["LastServiceDate"].Expression = "max
"Child.ServiceDate)";
setupColumn(0, csLastServ, 4, "Last Service Date",80);
// Add columns in display order (not necessarily database order)
ts.GridColumnStyles.Add(csCustID);
ts.GridColumnStyles.Add(csFirstName);
ts.GridColumnStyles.Add(csSurname);
ts.GridColumnStyles.Add(csAddress);
ts.GridColumnStyles.Add(csLastServ);
// Add it to the datagrid's TableStyles collection
dgCustList.TableStyles.Add(ts);
}
private void setupColumn(int table, DataGridColumnStyle col, int colNo,
String colName, int width)
{
col.MappingName = col.HeaderText =
dsCRSdata.Tables[table].Columns[colNo].ColumnName;
if (colName == "")
{
col.HeaderText = dsCRSdata.Tables[table].Columns[colNo].ColumnName;
}
else
{
col.HeaderText = colName;
}
col.Width = width;
}
Hope that helps
Maree
> Anybody does know about my problem. ???
>
[quoted text clipped - 7 lines]
>>
>> TIA