473,418 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

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 7410
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Pai | last post by:
hello there, I am trying to rersize the window it works find in IE but doea not work with mozilla window.attachEvent(onload,MWSOnLoad); window.onload = function (MWSOnLoad) { alert('hello');...
6
by: Brian | last post by:
Hi everyone, I'm writing a function (in javascript) that needs to do one thing if the page has not loaded, and another (different) thing if the page has already loaded. I'm looking for a way...
39
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
2
by: Ben Gracewood | last post by:
Hi I'm feeling like a total idiot at the moment. We're building an app in ..NET 2.0 beta 2, and no matter how hard I try, I can't get a DataGridView to accept ReadOnly = true on a cell or row....
6
by: pierre.bru | last post by:
hi, I encounter troubles with frames :( witht he folowing script in the _top page function walk(_frames) { for(var i=0; i<_frames.length; i++) { var frame = _frames; alert(frame.name);
10
by: p3t3r | last post by:
I have a treeview sourced from a SiteMap. I want to use 2 different CSS styles for the root level nodes. The topmost root node should not have a top border, all the other root nodes should have a...
0
by: TNSFED | last post by:
I have a dilemma when trying to delete a row from the DataGridView. Here is a sample of my code: private void dgv_EQUPS_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) {...
1
by: David | last post by:
I have a realtime stock quote system developed where I am updating a typed dataset with realtime quotes. I want my DataGridView control to show green forecolor when a price moves up and red...
5
by: Andrus | last post by:
Steps to reproduce issue: 1. Run code. 2. Enter some data to grid 3. Click other form caption 4. Click original form caption 5. Enter some characters Observed: entered characters are ignored
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.