all groups > dotnet windows forms databinding > july 2005 >
You're in the

dotnet windows forms databinding

group:

DataBindings.Add and BindingContext view


RE: DataBindings.Add and BindingContext view v-kevy NO[at]SPAM online.microsoft.com
7/29/2005 12:00:00 AM
dotnet windows forms databinding: Hi Aurin,

We have reviewed this issue and are currently researching on it. We will
update you ASAP. Thanks for your patience!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
DataBindings.Add and BindingContext view Aurin
7/29/2005 6:55:03 AM
See the code below. I have had some problems with setting databindings and
then not having them work. So I wrote the code below. It runs during the
constructor phase for the entire form. Is there a reason that these
databindings don’t appear in the output? What am I missing? Notice that
some of the bindings are to a relationship, not the table. But none of the
bindings are in the console output.

A second question: Is there a way to display (in console.writeline) the
navigation path used to specify the second parameter of the BindingContext[]
item key?

this.txtSerialNumber.DataBindings.Add(new
System.Windows.Forms.Binding("Text", this.dsTemplate,
"AssetInspection.SerialNumber"));
this.txtWRNo.DataBindings.Add(new System.Windows.Forms.Binding("Text",
this.dsTemplate, "AssetInspection.WRNo"));
this.txtStatus.DataBindings.Add(new System.Windows.Forms.Binding("Text",
this.dsTemplate, "AssetInspection.wrStatusCd"));
this.txtStopAfter.DataBindings.Add(new
System.Windows.Forms.Binding("Text", this.dsTemplate,
"AssetInspection.StopAfter"));
this.chkActive.DataBindings.Add(new
System.Windows.Forms.Binding("Checked", this.dsTemplate,
"AssetInspection.Active"));
this.txtNumberDone.DataBindings.Add(new
System.Windows.Forms.Binding("Text", this.dsTemplate,
"AssetInspection.NumberDone"));
this.txtIntervl.DataBindings.Add(new
System.Windows.Forms.Binding("Text", this.dsTemplate,
"AssetInspection.AssetInspectionAssetInspectionSch.Intervl"));
this.txtEarlyDeviation.DataBindings.Add(new
System.Windows.Forms.Binding("Text", this.dsTemplate,
"AssetInspection.AssetInspectionAssetInspectionSch.EarlyDeviation"));
this.txtLateDeviation.DataBindings.Add(new
System.Windows.Forms.Binding("Text", this.dsTemplate,
"AssetInspection.AssetInspectionAssetInspectionSch.LateDeviation"));
this.txtWhenDue.DataBindings.Add(new
System.Windows.Forms.Binding("Text", this.dsTemplate,
"AssetInspection.AssetInspectionAssetInspectionSch.InspectDueDec"));
this.fcboBasis.DataBindings.Add(new
System.Windows.Forms.Binding("SelectedValue", this.dsTemplate,
"AssetInspection.AssetInspectionAssetInspectionSch.Basis"));
this.dtpDateDue.DataBindings.Add(new
System.Windows.Forms.Binding("Value", this.dsTemplate,
"AssetInspection.AssetInspectionAssetInspectionSch.InspectDueDt"));
this.textBox1.DataBindings.Add(new System.Windows.Forms.Binding("Text",
this.dsTemplate,
"AssetInspection.AssetInspectionAssetInspectionSch.Intervl"));

ViewBindingContext(this.BindingContext);

private void ViewBindingContext (System.Windows.Forms.BindingContext bc)
{
int i = 1;
foreach (System.Collections.DictionaryEntry e in bc)
{
Console.WriteLine (" ");
Console.WriteLine ("Binding Context #" + i);
if (((WeakReference)e.Value).Target is CurrencyManager)
{
CurrencyManager cm = (CurrencyManager)((WeakReference)e.Value).Target;
Console.WriteLine ("Type:" + cm.GetType().ToString());
// How can I display the navigation path that is used for the second
parameter
/// of the BindingContext[dataset, "navpath"] item key???
if (cm.List is DataView)
{
Console.WriteLine("DataSet: "
+((DataView)cm.List).DataViewManager.DataSet.ToString());
Console.WriteLine("Table: " +((DataView)cm.List).Table.TableName);
}
if (cm.List is DataViewManager)
{
Console.WriteLine("DataSet: "
+((DataViewManager)cm.List).DataSet.ToString());
DataViewManager dvm = (DataViewManager) cm.List;
DataViewSettingCollection dvsc= dvm.DataViewSettings;
foreach (DataViewSetting s in dvsc)
{
Console.WriteLine (" " +s.ToString() + " " +s.Table.TableName);
string x = "";
}
}
foreach (Binding b in cm.Bindings)
{
Console.WriteLine (" " + b.Control.ToString());
Console.WriteLine (" Path:" +
b.BindingMemberInfo.BindingPath.ToString());
Console.WriteLine (" Member:" +
b.BindingMemberInfo.BindingMember.ToString());
Console.WriteLine (" Field:" +
b.BindingMemberInfo.BindingField.ToString());
}
}
else
{
BindingManagerBase bm =
(BindingManagerBase)((WeakReference)e.Value).Target;
}
i++;
}
}
RE: DataBindings.Add and BindingContext view v-jetan NO[at]SPAM online.microsoft.com (
8/1/2005 6:25:49 AM
Hi Aurin,

Thanks for your post.

I am not sure of what does " these databindings don't appear in the output"
mean. Based on my understanding, you want to bind many controls with simple
databinding with DataRelation. If so, I think you may refer to the link
below:
"4.20 How do I bind a TextBox to a nested relation?"
http://64.78.52.104/FAQ/WinForms/FAQ_c43c.asp#q1013q

There is a simple sample in this link showed us how to use relation
navigation path.

For your #2 question, I think you should have done the right thing. After
getting the currencymanager reference, we can use
Binding.BindingMemberInfo.BindingMember to get the navigation path. I used
the sample project to write the test code like below, which works well:
private void button1_Click(object sender, System.EventArgs e)
{
foreach(System.Collections.DictionaryEntry de in this.BindingContext)
{
Console.WriteLine(((WeakReference)de.Value).Target.GetType().ToString());
if(((WeakReference)de.Value).Target is BindingManagerBase)
{
BindingManagerBase
bmb=(BindingManagerBase)((WeakReference)de.Value).Target;
foreach(Binding b in bmb.Bindings)
{
Console.WriteLine(b.BindingMemberInfo.BindingMember );
}
}
}
}
If I misunderstand you, please feel free to tell me, thanks.
======================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
RE: DataBindings.Add and BindingContext view Aurin
8/1/2005 1:09:05 PM
The first 6 DataBindings are to a Table (AssetInspection).

The last 7 DataBindings are to a Relationship
(AssetInspection.AssetInspectionAssetInspectionSch)

They appear to work. But... "they don't appear in the output". By that I
mean the output generated by Console.Writeline.

[quoted text, click to view]
RE: DataBindings.Add and BindingContext view v-jetan NO[at]SPAM online.microsoft.com (
8/2/2005 8:21:09 AM
Hi Aurin,

Thanks for your feedback.

Have you tried the code snippet I provided in the last reply? Actually it
works well on my side.

If you still have problem, I suggest you create a little sample project to
help me reproduce out your problem. You can attach the sample project with
the reply. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
AddThis Social Bookmark Button