Hello all,
Form1 is bound to DataView1 and displays information for an account in text boxes.
Form 1 also has a Datagrid1 that is bound to array1 that holds detail info for the current account.
When the current account is changed Form1 has methods to update array1 and DataGrid1.
Form 2 is opened from a button on Form1. Form2 allows the user to search for accounts by filtering DataView1 and displays the results in DataGrid2 on Form2.
The user chooses an account in DataGrid2, hits "OK" button on Form2 and DataView1's BindingContext is set to the selected record and Form2 is closed.
How do I call Form1's methods to update array1 and DataGrid1 upon Form2 closing Do I need to do this with Delegates Is there a simpler way
Thank you
jmatt

Keeping forms in sync
J-Rock
In Form 2, use Private Event Form2Changed
In the form2 code, use Raisevent Form2Changed
in Form 1, define a method to handle Form2.Form2Changed
dsaniket
How does the DataGrid on Form2 get the records from Form1 Are you building a secondary datasource for Form2.DataGrid I guess what I'm getting at... when the user navigates through the records in Form2.DataGrid (which is a filtered view of Form1.DataGrid, right ) does the position in Form1 change as well I wouldn't think so, cause if it was bound in such a way (and I can't envision what that way would be) you wouldn't need this routine...
When you get strAcctNum in the above code, shouldn't you be pulling it from the currently selected record in Form2 rather than Form1 It looks to me like you're capturing the Account Number that was already selected in Form1 rather than the one the user just picked in Form2. So when you look it up to get the index, you're getting the same record you started with.
I may be way off here... I'm a VB coder so I'm trying to translate to the C#... I think it would be helpful to see how you are getting the records into Form2.
Also, bear in mind that you can execute this code from Form1 now if you want. Even after you've closed Form2, since you displayed it as a dialog, all of its objects are still available to the routine that called it. So before you do your other Form1 methods (after returning from Form2), you might do the above as well. Just call This.Close from FrmSearch_ButtonOK_Click.
pooya
If not, then in the Button.Click event in Form1 that calls Form2, use Form2.ShowDialog rather than just Form2.Show. Then you can call your Form1 methods afterword:
Private Sub ButtonOpenForm2.Click
Dim nForm as new Form2
nForm.ShowDialog
me.UpdateArray1
me.UpdateDataGrid1
End Sub
When you use ShowDialog, the current routine stops until the "dialog" form is closed.
<HR>
If the user must be able to manipulate Form1 while Form2 is open, but they can only open one Form2 at a time, you can declare a class wide Form2 variable in Form1 with events and then handle Form2.Closed from within Form1:
Public Class Form1
Dim WithEvents myForm2 as Form2
Private Sub Form1_Load() Handles MyBase.Load
'Prep your form
End Sub
Private Sub btnOpenForm2.Click() Handles btnOpenForm2.Click
myForm2=New Form2
myForm2.Show
End Sub
Private Sub Form2_Closed() Handles myForm2.Closed
'Execute your custom Form1 Methods
End Sub
End Class
But, if you need more than one Form2 at a time then I think you're stuck with delegates.
monfu
The user does not need to do anything with Form1 while Form2 is open so the ShowDialog suggestion is perfect!
Now I am experiencing a new issue! In the follwing code I
capture the current position in DataView1 after the user selects a row
find the ACCTNUM_FIELD value in that row
"unfilter " DataView1 and sort DataView1 on ACCTNUM_FIELD
reset the position for DataView1 with the Find method using ACCTNUM_FIELD
close Form2
******************************************************************
private void frmSearch_btnOK_Click(object sender, System.EventArgs e)
{
intRowIndex = BindingContext[frmFundAcctMaint.dvAccounts].Position;
strAcctNum = frmFundAcctMaint.dvAccounts[frmFundAcctMaint.ACCTNUM_FIELD].ToString();
[intRowIndex].RowfrmFundAcctMaint.dvAccounts.RowFilter = null;
frmFundAcctMaint.dvAccounts.Sort = frmFundAcctMaint.ACCTNUM_FIELD;
intRowIndex = frmFundAcctMaint.dvAccounts.Find(strAcctNum);
BindingContext[frmFundAcctMaint.dvAccounts].Position = intRowIndex;
this.Close();
}
*************************************************************************
The problem is when I get back to Form1 (frmFundAcctMaint) the current position of the DataView has not changed!
Any thoughts
Thank you
jmatt
jayant_jkn
I declared strAcctNum in Form2 to be public static. This variable is assigned the account number the user chooses from the filtered DataView1 on Form2. After Form2 closes my position in the unfiltered DataView1 is set by
DataView1.Find(strAcctNum)
This works!
I think that when position in a DataView is set from form code and that form is then closed, the position is reset to 0.
jmatt
G.Peters
This is my first major project using ADO.net so I am sort of feeling my way here.
DataView1 is an unfiltered view of Accounts. Form1 lets the user click one by one through DataView1.
Form2, when first opened, also is an unfiltered view of the same DataView1, shown in DataGrid2. On Form2 the user selects some filtering criteria from comboboxes and hits "Search". DataGrid2 then diplays filtered rows from DataView1 that fit the criteria. The user then picks a row in DataGrid2, hits "OK" , DataView1 is unfiltered, DataForm2 closes and Form1 displays the row in DataView1 selected by the user in Form2.
At least that's the goal! A couple of questions:
1. Is a filtered DataView1 still DataView1 In other words is the selected row in the filtered view still the selected row after unfiltering
2. If not how would you preserve the selection in the filtered view after unfiltering so that when you return to Form1 the selected record is displayed
My code was an attempt to this.
Thanks
jmatt
Jayson Go - Old Account
Yes, and no, if I understand you correctly. The dataview is still the same object, but any selected rows will be deselected becuase they may no longer meet the display criteria.
And I think you figured out the answer to your second question... that's how you got it to work. =)
Sorry so long in responding.