Hello all. I have a C#.Net 4.0 Winforms app. In a form I have a DataGridView bound to a BindingList<> of custom type ShippingRestrictionItem. The binding looks like this:
DataGridViewComboBoxColumn colRestrictions = (DataGridViewComboBoxColumn)this.dgvShippingRestrictions.Columns[0];
colRestrictions.DataPropertyName = "RestrictionId";
this._manipulator.DataBindGridColumn(colRestrictions, this._ds, "tblShippingRestrictionsLU", "ShippingRestriction", "pkShippingRestrictionId");
this.dgvShippingRestrictions.DataSource = this._container.Restrictions.ShippingRestrictions;
Everything binds up and displays fine. in fact, when a user adds a row and selects a value, it will be passed into the BindingList<> - eventually. My issue is that after the user adds a row I want to grab some data from the newly added row. Here's what the UserAddedRow currently looks like:
private void dgvShippingRestrictions_UserAddedRow(object sender, DataGridViewRowEventArgs e){
DataGridViewRow row = e.Row;
DataGridViewColumn col0 = row.Cells[0].OwningColumn;
string s = "UserAddedRow. Index: " + row.Index.ToString() + Environment.NewLine;
s += "State: " + row.State + Environment.NewLine;
s += "col0.Name: " + col0.Name + Environment.NewLine;
s += "col0.Value: " + row.Cells[0].Value.ToString() + Environment.NewLine;
s += "[0].Formattedvalue: " + row.Cells[0].FormattedValue.ToString() + Environment.NewLine;
s += "[0].EditedFormattedvalue: " + row.Cells[0].EditedFormattedValue.ToString() + Environment.NewLine;
s += "GetEditedFormattedValue: " + row.Cells[0].GetEditedFormattedValue(row.Index, DataGridViewDataErrorContexts.Display).ToString();
MessageBox.Show(s);
}
Okay, so NONE of the calls to retrieve data return anything. row.Cells[0].FormattedValue and row.Cells[0].EditedFormattedValue and row.Cells[0].GetEditedFormattedValue() all return an empty string, and the call to row.Cells[0].Value.ToString() returns a NULL and errors out.
MSDN lists all of the calls as appropriate to use from inside this event, so why do I get a whole lot of nothing? Is it a specific issue when binding to a BindingList<>? If I allow the event to play out, and then debug the underlying ShippingRestrictions
collection I *DO* see the newly added value, so it does get pushed to the list at some point.
Anyone see any glaring errors?
Thanks in advance.
Kurt