PC Review


Reply
Thread Tools Rate Thread

can't modify DataGridView in OnLoad() event

 
 
sklett
Guest
Posts: n/a
 
      27th Apr 2007
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


 
Reply With Quote
 
 
 
 
sklett
Guest
Posts: n/a
 
      28th Apr 2007
If it's any clue, my BindingComplete event never fires?

"sklett" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
OnLoad Event for a .Net DLL? David White Microsoft Dot NET Framework 4 4th Jul 2010 05:36 AM
Is there an onload event in Excel? loric Microsoft Excel Programming 2 5th May 2006 03:18 AM
onload event in XHTML Trevor L. Microsoft Frontpage 4 15th Jan 2006 02:09 PM
any event before OnLoad? Daves Microsoft ASP .NET 6 21st Mar 2005 03:31 PM
Onload event handler Brand Microsoft Frontpage 5 10th Apr 2004 09:31 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:58 AM.