473,763 Members | 1,382 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Form BindingContext object indexer problem?

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.BindingCon text[dataSet12, "employee"].Position += 1;

and this code will move the data in the datagrid:
this.BindingCon text[dataSet12.emplo yee].Position += 1;

If I do this, cm1 and cm2 are not equal:
CurrencyManager cm1 = (CurrencyManage r)
this.BindingCon text[dataSet12.emplo yee];
CurrencyManager cm2 = (CurrencyManage r) this.BindingCon text[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.DataS ource = dataSet12.emplo yee;
dataGrid1.DataM ember = <blank>

to

dataGrid1.DataS ource = dataSet12;
dataGrid1.DataM ember = "employee";

and then this works:
this.BindingCon text[dataSet12, "employee"].Position += 1;

Again, my question is why did I have to do this and why aren't these equal:
this.BindingCon text[dataSet12, "employee"].Position += 1;
this.BindingCon text[dataSet12.emplo yee].Position += 1;
Personally, I would rather use:
this.BindingCon text[dataSet12.emplo yee].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.DataBi ndings.Add("Tex t", DataSet1.Custom ers, "CustomerID ");

Dave
Nov 17 '05 #1
1 3320
Hi,

"D. Yates" <fo****@hotmail .com> wrote in message
news:e3******** ******@TK2MSFTN GP14.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.BindingCon text[dataSet12, "employee"].Position += 1;

and this code will move the data in the datagrid:
this.BindingCon text[dataSet12.emplo yee].Position += 1;

If I do this, cm1 and cm2 are not equal:
CurrencyManager cm1 = (CurrencyManage r)
this.BindingCon text[dataSet12.emplo yee];
CurrencyManager cm2 = (CurrencyManage r) this.BindingCon text[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.DataS ource = dataSet12.emplo yee;
dataGrid1.DataM ember = <blank>

to

dataGrid1.DataS ource = dataSet12;
dataGrid1.DataM ember = "employee";

and then this works:
this.BindingCon text[dataSet12, "employee"].Position += 1;

Again, my question is why did I have to do this and why aren't these
equal:
this.BindingCon text[dataSet12, "employee"].Position += 1;
this.BindingCon text[dataSet12.emplo yee].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+Data Member being the key
and BindingManagerB ase(CurrencyMan ager 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+Data Member 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(with out 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.BindingCon text[dataSet12.emplo yee].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.DataBi ndings.Add("Tex t", DataSet1.Custom ers, "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

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1522
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 reflection to use the indexer property, or is there some sort of casting that I can do? I would like to do something like this.
6
1691
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 has been failing. System.Data.DataRowView drvCurrent; System.Data.DataView dvNew; dvNew = new System.Data.DataView(); drvCurrent = (System.Data.DataRowView)this.ds1.Message; dvNew.Table = this.ds1.Message; dvNew.RowFilter="MessageID = '"...
18
3351
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 columns, "scode" and "sname", as 1 column (if not possible then 2 columns will be fine) in the listbox. Can the listbox display 2 columns information from the dataset and how can I do that? Also, I set the property of the listbox to selectionmode...
5
5913
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 changing the size of the form The code is at the following location in the January, 2004 help ms-help://MS.VSCC.2003/MS.MSDNQTR.2004JAN.1033/cpref/html/frlrfSystemWindowsFormsDataGridClassTopic.ht You can also find it by doing a search for...
12
1767
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 CurrentChanged event from the BindinManager on a Winform never occurs with framework V1.1. and it is not possible from the bindings to know if the user has done some modifications.
1
1456
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 textboxes however when clicking either of the buttons, nothing happens - the data from the next/previous rows does not re-populate the textboxes. This is an extremely simple situation yet I cannot figure out what is going wrong. Can anyone help? I've...
0
1387
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 datagridForm from my mainForm:
5
3113
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 ParentTable and the rest are children. For Example: The form shows the Customer and their most recently added Contact (in textboxes, not in a DataGrid). When I click the Add button on the form, I enumerate through all of the DataTables in the...
1
2134
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 rows to dataset the save button works when i remove some of them the update method doesn't work. Please see the following code: public Popola() { InitializeComponent(); string connstring = "Data Source =...
0
9563
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10145
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9998
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9822
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7366
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.