473,379 Members | 1,302 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,379 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 1484

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...
0
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.