Answer the question
In order to leave comments, you need to log in
How in Visual Basic(e) to force two or more forms to work with one Object Data Source?
Greetings to all Khabrovchan!
I want to write a small program in Visual Basic, without using a database connection, but with the ability to save some reference data. I created two forms, one main for working with data, the second for entering reference information, then I created a module with the "Data Set" type, let's call StoreDB, where I added an SPR Table with two text columns. In the menu "Project" - "Add data source" - "Object" marked the created StoreDB module. I threw BindingSource1 on the first form in the DataSource property using the StoreDB drop-down list with the DataMember=Spr property field, then I connect the Grid with BindingSource1. I run it for execution, everything seems to be fine, you can enter data into the table. Now I repeat the procedure with the second form, throw BindingSource1, specify DataSource=StoreDB, DataMember=Spr, I place Grid I connect with BindingSource1. In the first form I make a call to show the Second form. I start the project, the main form with a table appears, I drive in the data, I press the button to show Form2, a form appears with an empty table, although in theory the data that I entered in Form1 should have appeared there. Well, I enter data back into Foma2, but this data is not reflected in Form1. After digging around, I came to the conclusion that for each form, Visaul Studio creates an instance of the StoreDb object, which is not necessary at all, I assumed that the StoreDb object would be one as a data source. I tried to place the StoreDb object in Form1 (it appeared in the toolbar) which I threw on the form, but the second form BindingSource1 stubbornly does not want to see it. I drive in the data, I press the button to show Form2, a form appears with an empty table, although in theory there should have appeared the data that I entered in Form1. Well, I enter data back into Foma2, but this data is not reflected in Form1. After digging around, I came to the conclusion that for each form, Visaul Studio creates an instance of the StoreDb object, which is not necessary at all, I assumed that the StoreDb object would be one as a data source. I tried to place the StoreDb object in Form1 (it appeared in the toolbar) which I threw on the form, but the second form BindingSource1 stubbornly does not want to see it. I drive in the data, I press the button to show Form2, a form appears with an empty table, although in theory there should have appeared the data that I entered in Form1. Well, I enter data back into Foma2, but this data is not reflected in Form1. After digging around, I came to the conclusion that for each form, Visaul Studio creates an instance of the StoreDb object, which is not necessary at all, I assumed that the StoreDb object would be one as a data source. I tried to place the StoreDb object in Form1 (it appeared in the toolbar) which I threw on the form, but the second form BindingSource1 stubbornly does not want to see it. After digging around, I came to the conclusion that for each form, Visaul Studio creates an instance of the StoreDb object, which is not necessary at all, I assumed that the StoreDb object would be one as a data source. I tried to place the StoreDb object in Form1 (it appeared in the toolbar) which I threw on the form, but the second form BindingSource1 stubbornly does not want to see it. After digging around, I came to the conclusion that for each form, Visaul Studio creates an instance of the StoreDb object, which is not necessary at all, I assumed that the StoreDb object would be one as a data source. I tried to place the StoreDb object in Form1 (it appeared in the toolbar) which I threw on the form, but the second form BindingSource1 stubbornly does not want to see it.
Well, the question is:
How in Visual Basic (e) to make two or more forms work with one Object Data Source?
Thanks to those who responded (damn, I've been fighting for the second day)?
Answer the question
In order to leave comments, you need to log in
At closing of the main form I do DataSet.WriteXML.
I dug up all kinds of manipulations:
If you place a StoreDb object (data source) on the main form, then link it to the BindingSource1 of the same form, and when you call Form2 on which there is also a BindingSource1, programmatically bind it to the StoreDb of the first form, then form2 works with a single Data Source that is on Form1 . those.
Private Sub ToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles ToolStripMenuItem1.Click 'Event Form1
Form2.BindingSource1.DataSource = ApP_DB1
Form2.ShowDialog()
End Sub
But the premonition is tormenting that there should still be a simpler mechanism, somehow in the designer to indicate that form2 itself would bind to the Data Source object in form1.
PS
Thank you for responding!
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question