Hi all,
I've 2 form.. let say form 1 have datagridview that bind with datatable from dataset I create on designer mode. and form 2 have textbox to fill with data that bind with datatable from record user selected in form 1.
Example when user press button 'add' on form 1 it will show form 2 and the record will be on new row position and after user fill the textbox and press button 'ok'.. how I can do the binding between two form.
It makes me confuse when I look on form load have the code like this
private void Currency_Load(object sender, eventargs e)
{
this.currencyTableAdapter.Fill(this.dataset.Currency)
}
this code automatically appears when I bind my datagridview with datatable when on designer mode.
Please guide me, cause I'm still new to C#.
Thanks.
Loading
Sam HobbsPosted Dec 19, 2011, 7:45 PM
Are you still working on this? I did not forget about it but I have been busy.
An alternative is to put everything into one form. You could show the data from one record on the same form; the data from the record could be the data for whatever row is selected in the DataGridView. Do you want to try that? Otehrwise I will still try to develop a way to do it the way you have asked for.
Andy WijPosted Dec 17, 2011, 8:33 AM
Before using bindingsource from designer mode, I've learn how to use dataset and datatable on runtime.
example:
private void Currency_Load(object sender, EventArgs e)
{
// my custom connection string class
Connection con = new Connection();
sql = "select * from Currency";
da = new SqlDataAdapter(sql, con.open_connection());
cb = new SqlCommandBuilder(da);
dt = new DataTable();
da.Fill(dt);
grid_currency.DataSource = dt;
myCurrencyManager = (CurrencyManager)this.BindingContext[dt];
}
With this I can passing datatable (dt) and currencymanager to form2 constructor so form2 textbox can be bind with the same record position.
But when I using databinding from designer mode, I got a little confuse about how to bind between two form.. Please help me.. :D
Pravin GhadgePosted Dec 17, 2011, 8:14 AM
private void Currency_Load(object sender, eventargs e)
{
this.currencyTableAdapter.Fill(this.dataset.Currency)
}
This code will automatically come becuase u have binded ur datagridiview with tableadapter in design time.
Andy WijPosted Dec 17, 2011, 8:05 AM
Example when user select one of the record list on datagridview and click button 'view' it will show form2 and the record detail will be show on form2..
and another problem is I confuse what's meaning of code on load_Event that automatically added when I bind datagridview with tableadapter on designer..
I hope you can understand what I mean cause I've bad english too.. hehe..
Pravin GhadgePosted Dec 17, 2011, 7:40 AM
have u tried my solution.
Andy WijPosted Dec 17, 2011, 7:14 AM
Thanks for the reply.. Yes u're correct.. datagridview on form1 is readonly so I'm using form2 to show the record detail, to insert new record and update record.
So my problem is when on form1 button add clicked, it show form2, on form2 user fill the textbox and click button 'ok'. form2 will be closed, record will be inserted to database and datagridview on form1 have new record showed.
On other word, the datagridview on form1 and textbox on form2 is binding on same bindingsource or datatable..
Sam HobbsPosted Dec 16, 2011, 4:22 PM
You say that you have a DataGridView in form1 and thre is an Add button also in form1. When the Add button is clicked you need to show form2 so the data can be entered for just one record. Is that much correct?
Congratulations on using a TableAdapter. I will try to help but please confirm that I understand correctly.
Pravin GhadgePosted Dec 16, 2011, 10:26 AM
On Form1:
USe Activated event:
private void Currency_Activated(object sender, EventArgs e)
{
this.currencyTableAdapter.Fill(this.dataset.Currency)
}
this may be help u.