473,322 Members | 1,690 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,322 software developers and data experts.

Trying to get datagridview to update from another form

BD
I have an MDI application with a datagridview on a childform1 that
will open childform2 with a double-click event on childform1.
Childform2 works on a record and upon closing I want the datagridview
on childform1 to update to reflect the changes. Currently, I close
childform1 forcing the user to reopen it to reflect the changes. I
have coded a method on childform1 to reload the table adapter but have
been unable to access it from childform2. The following code below is
a brief coding:

childform1:
public void DGVReload()
{
this.childform1tableadapter.fill(this.dataset.chil dform1);
}
childform2:
private void btnSave_Click(object sender, EventArgs e)
{
childform1.DGVReload();
}

Program will not compile and returns the following error code:
An object reference is required for the nonstatic field, method, or
property

I know there is a simple solution, but I honestly have not been
successful. Any help or direction is appreciated.

BDW

Nov 6 '08 #1
4 8897
You can do something like this in the form1

private void laneDataGridView_CellContentDoubleClick(object sender,
DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
DataRowView view =
laneDataGridView.Rows[e.RowIndex].DataBoundItem as DataRowView;
if (null != view)
{
DataRow row = view.Row;
BeginLaneEditing(row);
}
}
}

private void BeginLaneEditing(DataRow row)
{
if (null != row)
{
AddEditLaneForm frm = new
AddEditLaneForm(this.laneTypeTable, this.dummyDockListTable, false);
frm.LaneID = row["LaneID"].ToString();
frm.LaneName = row["LaneName"].ToString();
frm.LaneType = row["LaneType"].ToString();
frm.ShippingDock1 = (int)row["ShippingDock1"];

if (frm.ShowDialog() == DialogResult.OK)
{
row["LaneID"] = frm.LaneID;
row["LaneName"] = frm.LaneName;
row["LaneType"] = frm.LaneType;
row["ShippingDock1"] = frm.ShippingDock1;
}
}
}
Nov 6 '08 #2
BD
On Nov 6, 12:06*pm, Ashutosh Bhawasinka <discuss...@ashutosh.in>
wrote:
You can do something like this in the form1

private void laneDataGridView_CellContentDoubleClick(object sender,
DataGridViewCellEventArgs e)
* * * * {
* * * * * * * * if (e.RowIndex >= 0)
* * * * * * * * {
* * * * * * * * * * DataRowView view =
laneDataGridView.Rows[e.RowIndex].DataBoundItem as DataRowView;
* * * * * * * * * * if (null != view)
* * * * * * * * * * {
* * * * * * * * * * * * DataRow row = view.Row;
* * * * * * * * * * * * BeginLaneEditing(row);
* * * * * * * * * * }
* * * * * * * * }
* * * * }

* * * * private void BeginLaneEditing(DataRow row)
* * * * {
* * * * * * if (null != row)
* * * * * * {
* * * * * * * * AddEditLaneForm frm = new
AddEditLaneForm(this.laneTypeTable, this.dummyDockListTable, false);
* * * * * * * * frm.LaneID = row["LaneID"].ToString();
* * * * * * * * frm.LaneName = row["LaneName"].ToString();
* * * * * * * * frm.LaneType = row["LaneType"].ToString();
* * * * * * * * frm.ShippingDock1 = (int)row["ShippingDock1"];

* * * * * * * * if (frm.ShowDialog() == DialogResult.OK)
* * * * * * * * {
* * * * * * * * * * row["LaneID"] = frm.LaneID;
* * * * * * * * * * row["LaneName"] = frm.LaneName;
* * * * * * * * * * row["LaneType"] = frm.LaneType;
* * * * * * * * * * row["ShippingDock1"] = frm.ShippingDock1;
* * * * * * * * }
* * * * * * }
* * * * }
Sorry, my bad. I didn't explain why I was doing it this way. The
datagridview represents say open orders. The childform2 that it
opened is another form based on several tables tied by orderID
number. I am not directly editing the datagridview, that is why I
coded it the way I did. I am sure there is a better way, this way
seemed simpler to me. If I am not explaining correctly, please
advise.
BDW
Nov 6 '08 #3
I am not sure exactly what you meant, but let me try...you want to force
a update on form1 from form2.

If thats the case, create an event, say DataUpdated on Form2. Before
opening(showing) the form2, register for this event DataUpdated on form1.

now from form 2, whenever you want to force an update on form1, just
raise this event.

Actually this is the standard way for notifying the parent of anything
(changes).

Hope this make sense.

Thanks & Regards,
Ashutosh
Nov 6 '08 #4
BD
I think you hit my problem right on the nose. I am trying to update
form1 from form2 on closing form2. I was doing it in reverse. I was
setting up my update event on form1 and trying to call it from
form2.

Thank you very much for you help and assistance. Sometimes we think
too hard about a problem and totally miss the solution.

Again thanks,

BDW

Nov 6 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: bob | last post by:
Can anyone tell me the best way to update a dataset while it is being edited/viewed in the DataGridView control? Is this something that should be inserted into one of the grid's events? or should...
2
by: Ivan | last post by:
I have a class Foo which have two property. I have a thread that do some process and update class Foo int B. I have a datagridview on main form. this datagridview data source to this class Foo and...
11
by: Kevin | last post by:
I've been searching forever for examples of saving data changes in a DataGridView. There's all kinds of examples, but none really show how to save changes. Someone please help me. I have a...
7
by: John J. Hughes II | last post by:
I have a DataGridView with a TextBoxColumn. I setting the data source to a List<stringvalue in a static class. The list is filled from a background thread. So far all is fine and it works...
0
by: twigboy | last post by:
Hi all I have a strongly typed main form with a datagridview binded to an access database. On this main form I have a button that when clicked opens another form(open) to insert a new record into...
7
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is...
4
by: =?Utf-8?B?UmljaA==?= | last post by:
On a form - I have a datagridview which is docked to the entire form. The datagridview allows users to Delete and/or Add Rows. On the Form_Load event I Fill the datagridview source table with a...
11
by: dave18 | last post by:
Hello all! I found a solution to my original question, but there's still so much I don't understand about it, I thought I'd give this forum a try. At the very least, maybe it will help someone...
1
by: Arved Sandstrom | last post by:
This seems to be something so simple that none of the hundred-odd tutorials and forum threads that I have looked at (:-)) apparently thinks it's a problem. In a nutshell, I have two...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.