469,621 Members | 1,746 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,621 developers. It's quick & easy.

can't modify DataGridView in OnLoad() event

I've got a strange situation here. I have a databound DataGridView that
also has un-bound columns. When the view loads, I want to update the values
of the unbound columns. If I attempt to modify the unbound column's cells
in the OnLoad() handler the results are very strange. If I add a button to
my view and update the unbound cells in the butt's handler it works fine.

Here is an example of the code I'm trying to use (it's test code):
protected override void OnLoad(EventArgs e)
{
BuildOrderCollection orders = new BuildOrderCollection();
if(orders.LoadAll())
{
// Bind the first build order to the datagridview
BuildOrder order = orders[0] as BuildOrder;
buildOrderItemsBindingSource.DataSource =
order.BuildOrderItemCollectionByBuildOrderID;

// loop through the rows in the grid and try
// to change some cell values. Cells 0, 2 and 3 are NOT
// databound, only cell 1 is databound. If I attempt to
// modify the value of Cell 1 it will work, but if I try
// to change the row color or value of other cells it has
// no effect.
foreach(DataGridViewRow row in dataGridView_SNs.Rows)
{
row.DefaultCellStyle.BackColor = Color.GreenYellow; // has no
effect
row.Cells[1].Value = "I was changed in OnLoad!"; //
works
row.Cells[2].Value = "I was changed in OnLoad!"; // has
no effect
}
}

//_presenter.OnViewReady();
}
Here is the code I've added to a button click handler:
private void pictureBox_RefreshStatus_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow row in dataGridView_SNs.Rows)
{
row.DefaultCellStyle.BackColor = Color.GreenYellow;
row.Cells[2].Value = "I was changed in OnLoad!";
}

//_presenter.RefreshUnitStatus();
}
That code does EXACTLY what it should.

So my question is why won't this work in the same method where I'm setting
up the binding? Is it that the DataGridView isn't done "binding" yet so
it's overwriting my changes? It wouldn't be that because there is only one
databound column.

I don't get it, totally lost on this one. Any help would be greatly
appreciated.

Thanks,
Steve
Apr 27 '07 #1
1 7159
If it's any clue, my BindingComplete event never fires?

"sklett" <s@s.comwrote in message
news:uX**************@TK2MSFTNGP05.phx.gbl...
I've got a strange situation here. I have a databound DataGridView that
also has un-bound columns. When the view loads, I want to update the
values of the unbound columns. If I attempt to modify the unbound
column's cells in the OnLoad() handler the results are very strange. If I
add a button to my view and update the unbound cells in the butt's handler
it works fine.

Here is an example of the code I'm trying to use (it's test code):
protected override void OnLoad(EventArgs e)
{
BuildOrderCollection orders = new BuildOrderCollection();
if(orders.LoadAll())
{
// Bind the first build order to the datagridview
BuildOrder order = orders[0] as BuildOrder;
buildOrderItemsBindingSource.DataSource =
order.BuildOrderItemCollectionByBuildOrderID;

// loop through the rows in the grid and try
// to change some cell values. Cells 0, 2 and 3 are NOT
// databound, only cell 1 is databound. If I attempt to
// modify the value of Cell 1 it will work, but if I try
// to change the row color or value of other cells it has
// no effect.
foreach(DataGridViewRow row in dataGridView_SNs.Rows)
{
row.DefaultCellStyle.BackColor = Color.GreenYellow; // has no
effect
row.Cells[1].Value = "I was changed in OnLoad!"; //
works
row.Cells[2].Value = "I was changed in OnLoad!"; //
has no effect
}
}

//_presenter.OnViewReady();
}
Here is the code I've added to a button click handler:
private void pictureBox_RefreshStatus_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow row in dataGridView_SNs.Rows)
{
row.DefaultCellStyle.BackColor = Color.GreenYellow;
row.Cells[2].Value = "I was changed in OnLoad!";
}

//_presenter.RefreshUnitStatus();
}
That code does EXACTLY what it should.

So my question is why won't this work in the same method where I'm setting
up the binding? Is it that the DataGridView isn't done "binding" yet so
it's overwriting my changes? It wouldn't be that because there is only
one databound column.

I don't get it, totally lost on this one. Any help would be greatly
appreciated.

Thanks,
Steve


Apr 28 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Pai | last post: by
2 posts views Thread by Ben Gracewood | last post: by
6 posts views Thread by pierre.bru | last post: by
1 post views Thread by David | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.