473,397 Members | 2,077 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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 BindingNavigator 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 .PositionChanged
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 2131
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
INotifyPropertyChanged 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.com

"cjard" <mc**@aber.ac.ukwrote in message
news:11*********************@q75g2000hsh.googlegro ups.com...
Suppose:

A TextBox is bound to a BindingSource, which is bound to a DataTable
A BindingNavigator 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 .PositionChanged
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.guard.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
INotifyPropertyChanged 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
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...
4
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...
5
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...
4
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...
6
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,...
0
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...
7
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...
5
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...
5
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
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...

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.