Sharing one BindingSource.

Sharing one BindingSource.

Post by RGFu » Wed, 05 Apr 2006 01:44:03



What i would like to do is share on datasource with many forms, controls and
etc. but i having a problem, the binding only updates the targets when the
position of the datasource is changed (you will understand that after you see
the code below). so if change the description textbox the other textbox on
the other form wont update. only after i change the selected item in the
listbox. i even trying to use the same bindingcontext on each form but it is
not working. I hope someone can help me achieve this. below you can see an
example that its just like the way i trying.


Xml Data - C:\Data.xml
<project>
<name>LINQ</name>
<description>language-integrated query</description>
</project>
<project>
<name>C# 3.0</name>
<description>proposed changes to the C# language</description>
</project>

FormA ---
Public class FormA
{
Private DataSet _dataset;
Private Lixbox _list;
Private TextBox _text;

Public FormA(DataSet ds) : this()
{
This._dataset = ds;

This._list.DataSource = this._dataset.Tables[roject;
This._list.DisplayMember = ame
This._list.ValueMember = ame

This._text.DataBindings.Add(new
Binding(extthis._dataset.Tables[roject,escription;
}

private void _list_SelectedItemChanged(object sender, EventArgs e)
{
this.BindingContext{this._dataset, "Project"].Position =
this._list.SelectedIndex;
}
}

Main

[STAThread]
static Main(string[] args)
{
DataSet dataset = new DataSet();
dataset.ReadXml(@"C:\Data.xml");

BindingContext bin = new BindingContext();

FormA a1 = FormA(dataset);
FormA a2 = FormA(dataset);

a1.BindingContext = bin;
a2.BindingContext = bin;

a1.Show();

Application.Run(a2);
}
 
 
 

Sharing one BindingSource.

Post by U3BhcmtQbH » Fri, 26 May 2006 02:42:01


<snipped>

Hi Dan,

Try this method:

http://www.yqcomputer.com/

Let us know if your problem is fixed.

Mark