Dear NG Readers,
I have no idea if anyone follows up on a thread this old, but thanks to
Pete, Cor, Kav, and my own poking around I have solved this problem. The
key concept that I failed to grasp is that I should do all of the work in
code and stay away from the Collections Editor. Establish the DataGrid in
the form's design and do as little as possible in the design's property
sheet. Here is the code that worked:
private void btnGet_Click(object sender, System.EventArgs e)
{
decimal extPrice;
coHeader = CustomerOrderTbl.GetCoHeader(txtOrderNo.Text); //Load header
if (coHeader == null)
{
MessageBox.Show("Invalid customer order number.", "Entry error");
}
else
{
ShowData(); //display header
//Load line items into DataTable from SQL database
DataTable lineTable = CustomerOrderTbl.GetLines(txtOrderNo.Text);
//Label up the column headings
lineTable.Columns[0].ColumnName = "Order";
lineTable.Columns[1].ColumnName = "Seq.";
lineTable.Columns[2].ColumnName = "Part No.";
lineTable.Columns[3].ColumnName = "Ordered";
lineTable.Columns[4].ColumnName = "To Ship";
lineTable.Columns[5].ColumnName = "Shipped";
lineTable.Columns[6].ColumnName = "P/C";
lineTable.Columns[7].ColumnName = "Price";
lineTable.Columns[8].ColumnName = "Due Date";
lineTable.Columns[9].ColumnName = "Note";
lineTable.Columns[10].ColumnName = "Serial No.";
DataColumn dc = new DataColumn(); //New column for ext. price
dc.DataType = Type.GetType("System.Decimal");
lineTable.Columns.Add(dc);
dc.ColumnName = "Ext. Price";
foreach (DataRow dr in lineTable.Rows) //Form new column with ext. price
{
extPrice = Convert.ToDecimal(dr[3]) * Convert.ToDecimal(dr[7]);
dr[11] = extPrice;
}
grdLine.SetDataBinding(lineTable, ""); //Bind DataTable to DataGrid
}
} //end btnGet_Click()
Robert Schuldenfrei (bo*@s-i-inc.com)
"Pete Davis" <pdavis68@[nospam]hotmail.com> wrote in message
news:FY********************@giganews.com...
Yes. You'll need to give the column a name and add a DataGridTextBoxColumn
with a mapping name that matches to the DataGridTableStyles object your
grid is using.
If you create DataGridColumnStyles for the columns, then the grid will
only display the columns that have matching styles.
Pete