Disconnect controls that refer to the same dataset...

  • Thread starter Thread starter Jan Nielsen
  • Start date Start date
J

Jan Nielsen

Hi
I have a dataset that is bound to a combo on 1 form and a datagrid on
another form. I would like the combo and the datagrid to be disconnected.

It is like this.
I have a Main form with a "Send-Email-To-SelectedGroup-combo". When a group
is selected an email is generated to all members of the group.
The combo is a general combo (not in sync with rest of Main form)
If a person wants to add a new group to the combo I open a new form with a
datagrid showing all the groups. I send the dataset from the Main form to
the Add new group form
I send the dataset like this:
Sub OpenAddGroupForm
Dim frm As New FrmAddGroup()
frm.AssignDataset(Me.DsBoerneKirken1)
frm.ShowDialog()
End sub

The form AddGroupForm has a typed dataset as a local variable
Public Class AddGroupForm
Dim dsBoernekirkenAddGroup As Boernekirken_VB.DSBoerneKirken

Sub AssignDataset (byval inputDS as Boernekirken_VB.DSBoerneKirken)
dsBoernekirkenAddGroup = inputDS
End sub

sub AddGroupForm_Load
Datagrid.Datasource = dsBoernekirkenAddGroup
End sub
OR
Sub AddGroupForm_Load
Datagrid.Datasource = dsBoernekirkenAddGroup.TblAllowedGroup
End sub
OR
Sub AddGroupForm_Load
Datagrid.Datasource = dsBoernekirkenAddGroup
Datagrid..DataMember = "TblAllowedGroup"
End sub

Now THE PROBLEM:
Depending of which of the Loads I use When I
1) Sort on the columns in the datagrid or
2) delete or add new records to the datagrid the
"Send-Email-To-SelectedGroup-combo" on the MAIN form receives an
SelectedIndexChanged event so it sends an email (to a random group it seems)

How can I disconnect the combo on the main form from what happens in the
datagrid in the AddGroup form when they are bound to the same dataset?

Best regards

Jan
 
Hi Greg
Thanks for answering
I am not sure how I make bindingcontext for a combo or a datagrid.
(I actually tried to make one but I only succeeded in doing so for the
FrmAddGroup. And I could change the position for the bindingmanagerBase
which I verified referred to the correct table. But it did not affect the
position of the current row in the datagrid.


Jan
 
In reply to:

"How can I disconnect the combo on the main form from what happens in
the
datagrid in the AddGroup form when they are bound to the same dataset?
"

You have to create seperate BindingContexts for the two control...if
they share the same BindingContext that will respond to the same
changes. I would create a new one for the combobox and let the datagrid
use the exiting one.
 
Hi again Greg
I am not sure how to do this.
As far as I understand the BindingContext is created automatically when you
bind the combo. And I understand it like you can only create either a
general list or a bound list.
I have to create the Send Email combo as a general list or it will interfer
with the rest of my application.

Can I create a completely new, independent Bindingcontext for my Combo?
And how do I do it if I can?

Here is (some of) my combo code:
Me.cboSendEmails.BackColor = System.Drawing.Color.FromArgb(CType(224, Byte),
CType(224, Byte), CType(224, Byte))
Me.cboSendEmails.DataSource = Me.DsBoerneKirken1.ttilladtGruppe
Me.cboSendEmails.DisplayMember = "Gruppe"
Me.cboSendEmails.ValueMember = "TilladtGruppeID"

Best regards

Jan
 
Hi Greg
Just to make sure you understand this:
The combo does not have a Databinding

It is only used to send emails to the selected group.
Nothing is written to the dataset.

It seems to me you cannot have a BindingContext without a databinding (which
is actually what I want). Is this correct?

Furthermore the datagrid does not seem to have a Databinding even though it
is (automatically?) bound to the dataset through its DataSource property.

Jan
 
Now I have a separat BindingContext (or actually CurrencyManager) using a
dataview as datasource for the datagrid.
But a strange problem persists. When I add the first new record to the
datagrid the combo in the mainform changes to the first record if the
selectedindex of the combo is -1 (ie the combo is empty)

Well. I can live with that

Jan
 
Back
Top