M
Miro
'Sorry for the multi-newsgroup post - just really not sure which 'heading'
this relates to.
I am trying to switch the datasource/bindings to a reference on another form
during runtime. (vb.net)
Basically use the designer to create the form, let it add the dataset and
databindings to the form as it build it.
Then on sub new of the form2 switch the reference to the bindingsource and
dataset to the ones passed in from form1, and all
other controls should continue to work as is - since they all reference the
same fields from the dataset, just that the dataset and the
binding source points somewhere else now.
It did not work - the data shown in the datagrid is not the proper data.
(hope that makes sense)
Here is what I did:
I created 2 forms,
form2 on the Public Sub New() function I created some new parameters.
Form2:
Public Sub New( ByVal _xMyForm1BindingSource As BindingSource, ByVal
_xMyForm1Dataset As MyDataSet)
So from form1, i call form2 like this:
Dim fForm2 As New frmForm2( Me.FKBindingSource, Me.MyDataSetDS)
fForm2.ShowDialog()
So far so good.
Now I put a datagrid on form2, added this to the top of form2 so i can have
access to the passed in variables.
Private _MyDataSet As MyDataSet
Private _MyForm1BS As BindingSource
and within the SubNew of form2 i did this:
Form2:
Public Sub New( ByVal _xMyForm1BindingSource As BindingSource, ByVal
_xMyForm1Dataset As MyDataSet)
'Setting up references to the dataset and bindingsource ??
Me._MyDataSet = _xMyForm1Dataset
Me._MyForm1BS = _xMyForm1BindingSource
'Here is where the issue starts ****
'If i do this - this works
'myDataGridView is my datagridview on the screen
Me.myDataGridView.DataSource = Me._MyForm1BS 'This shows the proper data
in the datagridview from form1
'But ....if i rem out the line above, and go to the form2, forms editor,
click on the datagridview ( myDataGridView ) and then
'select a datasource, let it pop a dataset, bindingsource, and table adapter
to the form.
'Now here on the form I can use the gui wizards to setup my columns and
such...
then replacing the above line I was hoping to add references to the same
bindingsource ( which has the same tables )...i was under
the impression that the switch would be flawless and now the forms dataset
and bindingsource point to the dataset and binding source on form1.
'This does not work
'Me.MyNewForm2Dataset = Me._MyDataSet
'Me.MyNewForm2BindingSource = Me._MyForm1BS
'I was hoping this would set reference to my dataset and databinding sent
in, so it actaully points to the databindings from form1 during runtime, but
during design time, i have the full wizards at my disposal.
'It compiles and runs, but the data displaying in the datagridview is not
the data that displays if I code it manually.
EndSub
Is this even possible what I am attempting?
Thanks,
Miro
this relates to.
I am trying to switch the datasource/bindings to a reference on another form
during runtime. (vb.net)
Basically use the designer to create the form, let it add the dataset and
databindings to the form as it build it.
Then on sub new of the form2 switch the reference to the bindingsource and
dataset to the ones passed in from form1, and all
other controls should continue to work as is - since they all reference the
same fields from the dataset, just that the dataset and the
binding source points somewhere else now.
It did not work - the data shown in the datagrid is not the proper data.
(hope that makes sense)
Here is what I did:
I created 2 forms,
form2 on the Public Sub New() function I created some new parameters.
Form2:
Public Sub New( ByVal _xMyForm1BindingSource As BindingSource, ByVal
_xMyForm1Dataset As MyDataSet)
So from form1, i call form2 like this:
Dim fForm2 As New frmForm2( Me.FKBindingSource, Me.MyDataSetDS)
fForm2.ShowDialog()
So far so good.
Now I put a datagrid on form2, added this to the top of form2 so i can have
access to the passed in variables.
Private _MyDataSet As MyDataSet
Private _MyForm1BS As BindingSource
and within the SubNew of form2 i did this:
Form2:
Public Sub New( ByVal _xMyForm1BindingSource As BindingSource, ByVal
_xMyForm1Dataset As MyDataSet)
'Setting up references to the dataset and bindingsource ??
Me._MyDataSet = _xMyForm1Dataset
Me._MyForm1BS = _xMyForm1BindingSource
'Here is where the issue starts ****
'If i do this - this works
'myDataGridView is my datagridview on the screen
Me.myDataGridView.DataSource = Me._MyForm1BS 'This shows the proper data
in the datagridview from form1
'But ....if i rem out the line above, and go to the form2, forms editor,
click on the datagridview ( myDataGridView ) and then
'select a datasource, let it pop a dataset, bindingsource, and table adapter
to the form.
'Now here on the form I can use the gui wizards to setup my columns and
such...
then replacing the above line I was hoping to add references to the same
bindingsource ( which has the same tables )...i was under
the impression that the switch would be flawless and now the forms dataset
and bindingsource point to the dataset and binding source on form1.
'This does not work
'Me.MyNewForm2Dataset = Me._MyDataSet
'Me.MyNewForm2BindingSource = Me._MyForm1BS
'I was hoping this would set reference to my dataset and databinding sent
in, so it actaully points to the databindings from form1 during runtime, but
during design time, i have the full wizards at my disposal.
'It compiles and runs, but the data displaying in the datagridview is not
the data that displays if I code it manually.
EndSub
Is this even possible what I am attempting?
Thanks,
Miro