473,573 Members | 3,209 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Do bound controls receive any notification when the bound item is swapped for a different item?

Suppose:

A TextBox is bound to a BindingSource, which is bound to a DataTable
A BindingNavigato r is used to alter the current row being looked at by
the BindingSource
(i.e. Nav's NEXT button is pressed. BS.Position changes from 2 to 3,
Textbox was showing APPLE, now shows ORANGE)
Does the textbox receive any notification that this occurred? If so,
what?
I ask because I want to extend TextBox and add some extra properties.
When the textbox is showing an item off a DataRow whose .RowState is
Unchanged, i want to enable the TextBox. If the .RowState is Modified,
I want to make the TextBox disabled. If the .RowState is Added, I want
to make the Textbox ReadOnly.

If I can have the TextBox detect when the underlying row has changed
to another one, I can investigate the .RowState and change the state
of the TextBox accordingly.

Currently, I can implement this by hooking to the .PositionChange d
or .CurrentChanged events of the BindingSource, but I would prefer to
make it a TextBox internal thing

Thanks in advance

Jun 7 '07 #1
2 2145
Well, obviously the Binding instance updates the property on the textbox
when the value changes. There is no "special" notification that the textbox
receives though to change the property. From the textbox's point of view,
it's just another property change.

It's because of this that you don't want to make this a textbox-internal
thing because it's not the appropriate place.

What you are going to have to do is create a custom class which wraps a
DataRow instance. This class will expose a boolean property which indicates
whether or not the textbox should be enabled as well as implement the
INotifyProperty Changed interface. The class should hook up to the
appropriate events on the data table indicating when the row has changed, or
the row state has changed, and then change its property value accordingly.
Of course, you would also fire the PropertyChanged event when the value
changes in response to the event.

Then, you can just bind the Enabled property of the TextBox to the
property you expose, and it should work.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"cjard" <mc**@aber.ac.u kwrote in message
news:11******** *************@q 75g2000hsh.goog legroups.com...
Suppose:

A TextBox is bound to a BindingSource, which is bound to a DataTable
A BindingNavigato r is used to alter the current row being looked at by
the BindingSource
(i.e. Nav's NEXT button is pressed. BS.Position changes from 2 to 3,
Textbox was showing APPLE, now shows ORANGE)
Does the textbox receive any notification that this occurred? If so,
what?
I ask because I want to extend TextBox and add some extra properties.
When the textbox is showing an item off a DataRow whose .RowState is
Unchanged, i want to enable the TextBox. If the .RowState is Modified,
I want to make the TextBox disabled. If the .RowState is Added, I want
to make the Textbox ReadOnly.

If I can have the TextBox detect when the underlying row has changed
to another one, I can investigate the .RowState and change the state
of the TextBox accordingly.

Currently, I can implement this by hooking to the .PositionChange d
or .CurrentChanged events of the BindingSource, but I would prefer to
make it a TextBox internal thing

Thanks in advance

Jun 7 '07 #2
On Jun 7, 3:51 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guar d.caspershouse. comwrote:
Well, obviously the Binding instance updates the property on the textbox
when the value changes. There is no "special" notification that the textbox
receives though to change the property. From the textbox's point of view,
it's just another property change.
OK, maybe I dont have the data binding architecture correct in my head
then.. Previously I thought:

TextBox is databound
TextBox understands that it is databound
TextBox is told that the data model has changed
TextBox, being the View for the Model (MVC) requeries the model
TextBOx shows the new value from the model, in its view

Your comments indicate it is more like:

TextBox is databound
TextBox is ignorant of this
TextBox sits there and has values pushed into it by an externally
intelligent entity
This entity is not the model, but it receives notifications that the
model has changed, and pushes the changes into whatever viewing
controls are relevant
Changes to the textbox are communicated back to the entity.. how?
During Validation?

It's because of this that you don't want to make this a textbox-internal
thing because it's not the appropriate place.
OK, it makes more sense now that i can see textbox isnt intelligent
with regard to being a View in MVC concept.

What you are going to have to do is create a custom class which wraps a
DataRow instance.
You could say that I already have this, given that all my DataRow are
actually typed DataRow generated by .NET 2 DataSet Designer.
This class will expose a boolean property which indicates
whether or not the textbox should be enabled as well as implement the
INotifyProperty Changed interface. The class should hook up to the
appropriate events on the data table indicating when the row has changed, or
the row state has changed, and then change its property value accordingly.
Of course, you would also fire the PropertyChanged event when the value
changes in response to the event.

Then, you can just bind the Enabled property of the TextBox to the
property you expose, and it should work.
I thought about everything a little more deeply and I've hit a bump:

A new row that enters the dataset will always be state Added
A row that was filled from DB is Unchanged, but becomes Modified upon
changes
At some point in its life, a textbox is going to have to be enabled
regardless of the underlying row state (this is used for searching
within the app - all fields must be enabled)

Taking the real example of a Primary key field:

When the row is added, the value is unknown as it is assigned by the
database.
The field will be Enabled = False, ReadOnly = True

When the row is browsed after db download, editing should be
disallowed, but copy and paste operations allowed
The field will be Enabled = True, ReadOnly = True

When the row is used for searching, we are going to construct a
dynamic SQL where clause from this row, so we dont care if the user
edits the PK field else how would they search by PK?
The field will be Enabled = true, ReadOnly = false
DataTable has scope to make its DataColumn readonly, but I think youre
right in that this should be a property of a row.. So i can add some
extra properties to my already-typed rows, and bind the TextBox values
for .ReadOnly and .Enabled to those props. The props, internal to
DataRow, can change because they have knowledge of whether a row is
added, unch/modded or for_searching (another separate property i think
i'll have to add, yes?)

My question/bump is.. Will .NET 2's BindingSource raise any relevant
events to allow the textbox' bindings to not only read a change of
e.g. text value to show, but a change in these properties too? - You
mentioned the propertychanged event - how is this used with a
BindingSource?

Jun 7 '07 #3

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

Similar topics

19
4081
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate the code that implements managing unbound controls on forms given the superior performance of unbound controls in a client/server environment. I can...
4
2336
by: John Tyce | last post by:
The problem that I am now having, involves refreshing controls. I have allot of text boxes, several combo boxes and grids. These controls are showing live data from an Oracle database. I have dates in a combo box in my tool bar that are associated with the particular report that the user is opening. When the user picks a different date all of the...
5
4648
by: Aaron Ackerman | last post by:
I have a bound combobox the appears on a cell within the column of my bound grid when the user clicks on a cell n(In my vb.net WinForm app). I am trying to allow the adding of an item to that bound combo by allowing the user to dynamically type in the new value directly in the combo box whcih in turn updates the lookup table and then when they...
4
4606
by: jon f kaminsky | last post by:
Hi- I've seen this problem discussed a jillion times but I cannot seem to implement any advice that makes it work. I am porting a large project from VB6 to .NET. The issue is using the combo box bound to a table as a lookup, drawing values from another table to populate the available selections. This all worked fine in VB6. I have...
6
17152
by: ransoma22 | last post by:
I developing an application that receive SMS from a connected GSM handphone, e.g Siemens M55, Nokia 6230,etc through the data cable. The application(VB.NET) will receive the SMS automatically, process and output to the screen in my application when a message arrived. But the problem is how do I read the SMS message immediately when it arrived...
0
1450
by: HP | last post by:
Hi there I have a datalist control with some bound controls in its Item Template and a gridview bound to one of those fields (residing also in Item Template). I've found out that when I click Edit on the gridview (same happens when editing other gridview which is outside the datalist) all datalist bound fields (except the gridview)...
7
2993
by: | last post by:
I have what's probably a simple page lifecycle question related to dynamically evaluating values that are placed by a repeater and dynmically placing user controls that use those values. I'm attempting to bind a user control I've written, "ImageBox", to a repeater. The user control takes a custom property, "ContentID", that will execute...
5
2584
by: njb35 | last post by:
Hi all I'm beginning my foray from VBA into VB 2005 Express, and enjoying some of the efficiencies it provides! I'm stuck with some dataset handling however that I _think_ can be automated but I can probably code what I want to do the hard way. I've searching around online but can't find an answer to this specific question. Here's the...
5
9133
by: Ashutosh | last post by:
Hi, I have a un-typed table and 5 combo box on the form. All these combo box have this table as the data source. Now I want to be able to select different values using the 5 combo box. But when I change the value in one combo box, it changes the value in all other combo box. How can I make all the 5 combo box retain their individual...
0
7741
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...
0
7661
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7977
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. ...
1
7730
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6347
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5252
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...
0
3692
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...
1
2163
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
0
984
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.