I have a bound datagridview and I add 2 unbound columns and set the cell value for each row to "X" for the unbound PKG column and "Y" for the MISC column. When the window comes up, the 2 new columns are stil empty. I put a Msgbox to show that it does get there and it is populating the correct column. What am I missing?
// create new unbound columns
private void addUnboundCols()
{
addNewCol( "MISC", "Miscellaneous");
addNewCol( "PKG", "Package");
}
private void addNewCol(string name, string headertext)
{
DataGridViewTextBoxColumn newcol = new DataGridViewTextBoxColumn();
newcol.Name = name;
newcol.HeaderCell.Value = headertext;
newcol.ValueType = typeof(string);
newcol.Visible = true;
newcol.ReadOnly = false;
newcol.Frozen = false;
newcol.Width = 50;
dgvTbList.Columns.Add(newcol);
}
// put Y in Misc unbound col; and X in PKG col
private void setNewColData()
{
this.dgvTbList.EditMode = DataGridViewEditMode.EditProgrammatically;
foreach (DataGridViewRow dgvrow in dgvTbList.Rows)
{
dgvrow.Cells["MISC"].Value = "Y";
dgvrow.Cells["PKG"].Value = "X";
// now just to make sure the date was added it to the right place
object val = dgvrow.Cells["PKG"].Value;
string hdr = dgvrow.Cells["PKG"].OwningColumn.HeaderText;
MessageBox.Show(hdr + " val= " + val.ToString()); // this comes out correct
}
dgvTbList.EditMode = DataGridViewEditMode.EditOnKeystrokeOrF2;
this.Refresh();
}