Forms Databinding Question

G

Guest

This question refers to:

http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q313482

First question:
The following code binds a TextBox control and a DataGrid control to the
same CurrencyManager and DataView: TextBox1.DataBindings.Add("Text", ds,
"Customers.CustomerID")
DataGrid1.DataSource = ds
DataGrid1.DataMember = "Customers"

Alternatively, you can use the following code to bind to different
CurrencyManager and DataView objects: TextBox1.DataBindings.Add("Text",
ds.Tables("Customers"), "CustomerID")
DataGrid1.DataSource = ds.Tables("Customers")

Each of the preceding code samples displays the same data. Edits and
scrolling are not synchronized between examples but are synchronized in them.

I can't see what would cause the first example to share a common currency
manager while the 2nd example would make use of two different
currencymanagers. I'm guessing it has something to do with the placement of
the table in the two examples that causes datasource overlapping in the first
but not in the second example, but I was hoping I could get some elaboration
You can use the Microsoft Visual Studio .NET integrated development
environment (IDE) to bind controls at design time to any class that supports
the IComponent interface. You can also bind at run time.
How does one bind at runtime? It seems like all the examples show design
time binding. Am I mistaken?

Thanks...

-Ben
 
K

Kevin Yu [MSFT]

Hi Ben,

1. As far as I know, we can share the CurrencyManager between the datagrid
and TextBox in both two cases. When getting the CurrencyManager, we just
need to specify the exact data source as you do the databinding.

2. As you can see, the code snippet you have posted is using the runtime
binding. When you set the data sources in the property window, the schema
information will be show on the controls(for example, a datagrid) at design
time. The binding code is genereted in the Windows form designer genereted
code region. And the schema will the shown in the windows form designer.
However, the data will be filled in at runtime. For runtime binding,
everything will be done at runtime. There is not much difference between
them.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top