D
D. Yates
Hi,
I retrieved the employee table from the Pubs database into a single dataset
called, dataSet12. I dropped two textbox controls and a datagrid control
onto the same form and bound the controls at design time to dataSet12's
employee table. Now I want to move through the data by pressing a
button....
This code will change the data in the text boxes:
this.BindingContext[dataSet12, "employee"].Position += 1;
and this code will move the data in the datagrid:
this.BindingContext[dataSet12.employee].Position += 1;
If I do this, cm1 and cm2 are not equal:
CurrencyManager cm1 = (CurrencyManager)
this.BindingContext[dataSet12.employee];
CurrencyManager cm2 = (CurrencyManager) this.BindingContext[dataSet12,
"employee"];
if (cm1 == cm2)
cm1.Position++;
cm1 and cm2 are never equal. Why are they different?
I fixed my problem by changing the design property of the datagrid from
dataGrid1.DataSource = dataSet12.employee;
dataGrid1.DataMember = <blank>
to
dataGrid1.DataSource = dataSet12;
dataGrid1.DataMember = "employee";
and then this works:
this.BindingContext[dataSet12, "employee"].Position += 1;
Again, my question is why did I have to do this and why aren't these equal:
this.BindingContext[dataSet12, "employee"].Position += 1;
this.BindingContext[dataSet12.employee].Position += 1;
Personally, I would rather use:
this.BindingContext[dataSet12.employee].Position += 1;
since it doesn't require a internal table lookup. It is also the code shown
on page 328 of the MCAD/MCSD Self pace training kit for test 70-306/70-316.
The books example works because he is demonstrating runtime data binding and
he binds his text boxes with code that looks like this:
TextBox1.DataBindings.Add("Text", DataSet1.Customers, "CustomerID");
Dave
I retrieved the employee table from the Pubs database into a single dataset
called, dataSet12. I dropped two textbox controls and a datagrid control
onto the same form and bound the controls at design time to dataSet12's
employee table. Now I want to move through the data by pressing a
button....
This code will change the data in the text boxes:
this.BindingContext[dataSet12, "employee"].Position += 1;
and this code will move the data in the datagrid:
this.BindingContext[dataSet12.employee].Position += 1;
If I do this, cm1 and cm2 are not equal:
CurrencyManager cm1 = (CurrencyManager)
this.BindingContext[dataSet12.employee];
CurrencyManager cm2 = (CurrencyManager) this.BindingContext[dataSet12,
"employee"];
if (cm1 == cm2)
cm1.Position++;
cm1 and cm2 are never equal. Why are they different?
I fixed my problem by changing the design property of the datagrid from
dataGrid1.DataSource = dataSet12.employee;
dataGrid1.DataMember = <blank>
to
dataGrid1.DataSource = dataSet12;
dataGrid1.DataMember = "employee";
and then this works:
this.BindingContext[dataSet12, "employee"].Position += 1;
Again, my question is why did I have to do this and why aren't these equal:
this.BindingContext[dataSet12, "employee"].Position += 1;
this.BindingContext[dataSet12.employee].Position += 1;
Personally, I would rather use:
this.BindingContext[dataSet12.employee].Position += 1;
since it doesn't require a internal table lookup. It is also the code shown
on page 328 of the MCAD/MCSD Self pace training kit for test 70-306/70-316.
The books example works because he is demonstrating runtime data binding and
he binds his text boxes with code that looks like this:
TextBox1.DataBindings.Add("Text", DataSet1.Customers, "CustomerID");
Dave