472,805 Members | 3,675 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

An Interesting use of data binding

I am not sure how many are aware of this sort of data binding,
but as it is new to many (classic) VB developers I thought I
would post this once just to let people know of its availablility.

There are cases where properties of one object is dependant on
a property of another object. For a common example, when you
bind an ArrayList to a ComboBox using the combo's DataSource
property, the combo box fills up with items from the array list.

Attaching a property of one control to the property of another
is also possible using binding. For example, if you have a
checkbox as an option, and a few other controls that should be
enabled when that checkbox is checked, you can do that by
writing appropreate code in the checkbox changed event, or you
can do it using data binding.

In this case you can bind the Enabled property of the secondary
control(s) to the Checked property of the checkbox. There is
also the possiblility of inserting code into the binding process
to be called when the change is underway.

I have included an example of both methods below. A simple
binding of the two controls, is just one line of code. To
show how to insert code into the process, I've bound one
textbox that is enabled when the checkbox is checked, and
another Textbox that is disabled when the checkbox is checked.

To see it in action, add two Textboxes and a Checkbox to a new
form and paste in the code below.

I just thought it was rather neat and tidy where one line of
code binds the two controls, instead of filling a Changed
event (handler) with the needed code....

Enjoy!
LFS

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Checked/enabled, not checked/not enabled
TextBox1.DataBindings.Add(New Binding("Enabled", CheckBox1, "Checked"))
TextBox1.Text = "Simple"

' Checked/Not enabled, not checked/enabled
Dim binder As Binding = New Binding("Enabled", CheckBox1, "Checked")
AddHandler binder.Format, AddressOf InvertBoolean
TextBox2.DataBindings.Add(binder)
TextBox2.Text = "Inverted"
End Sub

Public Sub InvertBoolean(ByVal Sender As Object, ByVal cEvent As ConvertEventArgs)
If cEvent.Value.GetType Is GetType(Boolean) Then
cEvent.Value = Not CType(cEvent.Value, Boolean)
End If
End Sub


Nov 21 '05 #1
0 1428

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

Similar topics

0
by: Ann Morris | last post by:
INTRODUCTION One of the most powerful aspects of .NET and Windows Forms is data binding. Data binding is the process of associating user interface (UI) elements with a data source to generate a...
16
by: D Witherspoon | last post by:
I am developing a Windows Forms application in VB.NET that will use .NET remoting to access the data tier classes. A very simple way I have come up with is by creating typed (.xsd) datasets. For...
0
by: NicK chlam via DotNetMonster.com | last post by:
this is the error i get System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. at System.Data.Common.DbDataAdapter.Update(DataRow dataRows, DataTableMapping tableMapping) at...
19
by: Simon Verona | last post by:
I'm not sure if I'm going down the correct route... I have a class which exposes a number of properties of an object (in this case the object represents a customer). Can I then use this...
1
by: Steve Lutz | last post by:
I have written a web service to provide some back-end functionality to a Web Site. The web service returns lists of items. If I use the webservice via a browser, it works fine and returns the...
19
by: Larry Lard | last post by:
In the old days (VB3 era), there was a thing called the Data Control, and you could use it to databind controls on forms to datasources, and so (as the marketing speak goes), 'create database...
0
by: mjsterz | last post by:
I've been working with VB .NET for less than a year and this is the first time I've posted on one of these groups, so let me apologize beforehand if I'm being unclear, not posting my issue...
14
by: Rolf Welskes | last post by:
Hello, I have an ObjectDataSource which has as business-object a simple array of strings. No problem. I have an own (custom) control to which I give the DataSourceId and in the custom-control...
9
by: Anil Gupte | last post by:
After reading a tutorial and fiddling, I finally got this to work. I can now put two tables created with a DataTable class into a DataRelation. Phew! And it works! Dim tblSliceInfo As New...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.