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 1 3285
Hi,
"D. Yates" <fo****@hotmail.com> wrote in message
news:e3**************@TK2MSFTNGP14.phx.gbl... 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;
Basicly that's how it is designed though it may be confusing. It's not
enough that both databindings end up with the same data, when you ask a
BindingContext for a CurrencyManager then you must use the exact same
DataSource and DataMember (excluding fieldname) then the ones you used for
the binding.
A BindingContext is basicly a map with DataSource+DataMember being the key
and BindingManagerBase(CurrencyManager or PropertyManager) being the value.
Each time you bind a list to some Control it needs a CurrencyManager to
maintain the position, so it checks whether the BindingContext already
contains a CurrencyManager for that DataSource+DataMember and if it does
then it uses the existing one, otherwise it creates a new CurrencyManager.
That should also explain why they can navigate together or independent.
So a combination of DataSource and DataMember(without fieldname) is the key
but there is _no_ resolving to see whether this points to the same data or
not.
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");
Yes, but if you use a typed DataSet then then the designer won't let you
bind TextBox's directly to a DataTable, it will always use the DataSet as
the DataSource.
HTH,
greetings Dave This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Brian Takita |
last post by:
Hello,
I am able to test an object to see if it is an indexer (IsIndexer
function), however I don't know how to call the indexer without Unboxing
to the object's class.
Do I need to use...
|
by: Esteban404 |
last post by:
I'm trying to create a preview shot of a record being edited, so I want to
take the current state and pass it to a instance of a form I have. I've tried
to create a dataView and pass that, but it...
|
by: Alpha |
last post by:
Hi,
I'm working on a Windows applicaton with VS 2003 on windows 2000. I have a
listbox that I have binded to a dataset table, "source" which has 3 columns.
I would like to display 2 of those...
|
by: Genojoe |
last post by:
I am using code from Help with two exceptions. (1) I increased the number of sample rows from 3 to 20, and (2) I anchored the datagrid to bottom of form so that I can change the size of the grid by...
|
by: ABC - Sébastien Beaugrand |
last post by:
Hi,
I've been trying to get an answer from french newsgroup but I did'nt succeed
in this, so I'll try on this group and sorry for my poor english.
The description of the bug :
The...
|
by: VictorT |
last post by:
Hi All,
I am trying to create a simple Windows form that lists a users' data
one user at a time with the usual "Next" & "Previous" buttons.
Upon loading the form, I am able to populate all...
|
by: Ben |
last post by:
module main
...
application.run(new splashform)
..
end module
after a few screen, I try to load a new codes I got from MSDN on datagrid
that works on its own. I took out submain and ran...
|
by: Aspnot |
last post by:
Background:
I have a data entry form that is bound to a DataSet. This DataSet contains
9 tables and the form displays data from each table in textboxes, not a
DataGrid. One of the tables in the...
|
by: Pietro Ova |
last post by:
Hello,
I wrote a little program to understand the ADO.NET's mechanism. It's a common program with a datagrid, textboxes and a toolstripbar with usually buttons. The problem is that meanwhile i add...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |