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(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
' Checked/enabled, not checked/not enabled
TextBox1.DataBi ndings.Add(New Binding("Enable d", CheckBox1, "Checked"))
TextBox1.Text = "Simple"
' Checked/Not enabled, not checked/enabled
Dim binder As Binding = New Binding("Enable d", CheckBox1, "Checked")
AddHandler binder.Format, AddressOf InvertBoolean
TextBox2.DataBi ndings.Add(bind er)
TextBox2.Text = "Inverted"
End Sub
Public Sub InvertBoolean(B yVal Sender As Object, ByVal cEvent As ConvertEventArg s)
If cEvent.Value.Ge tType Is GetType(Boolean ) Then
cEvent.Value = Not CType(cEvent.Va lue, Boolean)
End If
End Sub 0 1530 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 visual representation
of data. Two types of data binding are available for Windows Forms:
Simple Data Binding and Complex Data Binding.
Simple data binding allows you to bind one data element to a control.
In many situations you want to display...
|
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 example dsParts.xsd and including that in the data tier. I then will
create a class that looks like this
Public Class CPart
Inherits dsParts
|
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 System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String
srcTable)
at System.Data.Common.DbDataAdapter.Update(DataSet dataSet)
at TryThis.Form1.save() in C:\Documents and Settings\Nick\My Documents\...
|
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 object to
databind to text boxes etc?
I can't use a dataset as the object has loads of derived logic, for example
updating one property may actually update several database fields for
example.
|
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 results
in XML.
I then created the proxy for the Web Service in VS.NET. I can call the
webmethod fine and get an array of Items. (Although it's a local class to
the WebSite).
When I attempt to have a repeater control list the reults in a web form,...
| |
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 applications without
writing a single line of code!!!'. Personally, and I know I wasn't
alone in this, I was always suspicious of this claim, because one
invariably ended up writing huge amounts of code attempting to get the
automagical thing to do...
|
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 correctly,
posting to the wrong forum, or committing some other sort of faux pas.
My team is developing a Windows Forms application using VS 2005 with
SQL Server 2005 on the back end and we're having a problem using
ComboBoxes data bound to lookup...
|
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 so I get the ObjectDataSource. No problem
.....
ObjectDataSource src = .... //is ok i have it
|
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 DataTable("SliceInfo")
Dim tblSliceRatings As New DataTable("SliceRatings")
'.... All the adding datacolumns, datarows, etc. goes here..
DatasetInit.Tables.Add(tblSliceInfo)
|
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...
|
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...
| |
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...
|
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...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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: 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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |