473,770 Members | 5,862 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Databinding a control to the negative of a bool property

I posted this message to another board and have hardly had any views on it,
leave alone answers. So I am cross-posting here.

This may be a very simple question but I can't get my head around it.

I have a textbox's enabled property bound to the IsNew property of an object.

this.txtPhone1. DataBindings.Ad d("Enabled", this.BindingSou rce, "IsNew", true);

So when the IsNew property is true, my textbox is enabled. This is correct
behavior.

However, I want to reverse this behavior. In other words, I'd like to bind
the enabled property to !IsNew, so that the textbox is disabled, when the
IsNew property is true. How can I do this without creating a new property on
the object that returns !IsNew??

Thanks,

Naveen
Dec 10 '06 #1
7 2015
Naveen,

I assume that the IsNew property has 2 stati.

True and false.

Therefore your binding says when it is false.
("Enabled", this.BindingSou rce, Property , true);
Textbox.Enabled = false;

The IsNew in your binding is only an address, it has no sense to set that
negative.

Cor
"Naveen" <Na****@discuss ions.microsoft. comschreef in bericht
news:3F******** *************** ***********@mic rosoft.com...
>I posted this message to another board and have hardly had any views on it,
leave alone answers. So I am cross-posting here.

This may be a very simple question but I can't get my head around it.

I have a textbox's enabled property bound to the IsNew property of an
object.

this.txtPhone1. DataBindings.Ad d("Enabled", this.BindingSou rce, "IsNew",
true);

So when the IsNew property is true, my textbox is enabled. This is correct
behavior.

However, I want to reverse this behavior. In other words, I'd like to bind
the enabled property to !IsNew, so that the textbox is disabled, when the
IsNew property is true. How can I do this without creating a new property
on
the object that returns !IsNew??

Thanks,

Naveen


Dec 10 '06 #2
Cor,
Thanks for your reply. I'm not sure I fully understand your reply.Let me
explain in a little detail.

1) A textbox is bound to an object.

2) The object has an IsNew property.
private bool _isNew = false;
public bool IsNew
{
get{return _isNew;}
set{_isNew = value}
}

3) I need to bind the enabled property of a textbox to the negative of the
value of IsNew. i.e. if IsNew = true, I want the textbox.Enabled = false and
if IsNew = false, I want textbox.Enabked = true.
Obviously I would like to do this in 1 databinding statement, without any if
statements. This enables me to set the databinding and forget about it,
because I'll have the DataSourceUpdat eMode to OnPropertyChang ed.

So this statement,

this.txtPhone1. DataBindings.Ad d("Enabled", this.BindingSou rce, "IsNew",
true, DataSourceUpdat eMode.OnPropert yChanged);

does the exact reverse of what I need. It sets txtPhone1.Enabl ed = true if
IsNew = true and vice-versa.

I guess my question is, is there a way to change this statement to set
txtPhone1.Enabl ed = true, if IsNew = false and vice-versa??

Thanks,
Naveen

"Cor Ligthert [MVP]" wrote:
Naveen,

I assume that the IsNew property has 2 stati.

True and false.

Therefore your binding says when it is false.
("Enabled", this.BindingSou rce, Property , true);
Textbox.Enabled = false;

The IsNew in your binding is only an address, it has no sense to set that
negative.

Cor
"Naveen" <Na****@discuss ions.microsoft. comschreef in bericht
news:3F******** *************** ***********@mic rosoft.com...
I posted this message to another board and have hardly had any views on it,
leave alone answers. So I am cross-posting here.

This may be a very simple question but I can't get my head around it.

I have a textbox's enabled property bound to the IsNew property of an
object.

this.txtPhone1. DataBindings.Ad d("Enabled", this.BindingSou rce, "IsNew",
true);

So when the IsNew property is true, my textbox is enabled. This is correct
behavior.

However, I want to reverse this behavior. In other words, I'd like to bind
the enabled property to !IsNew, so that the textbox is disabled, when the
IsNew property is true. How can I do this without creating a new property
on
the object that returns !IsNew??

Thanks,

Naveen


Dec 10 '06 #3
Add another property for IsNotNew and bind to that.

Robin S.
--------------------------------------
"Naveen" <Na****@discuss ions.microsoft. comwrote in message
news:5B******** *************** ***********@mic rosoft.com...
Cor,
Thanks for your reply. I'm not sure I fully understand your reply.Let
me
explain in a little detail.

1) A textbox is bound to an object.

2) The object has an IsNew property.
private bool _isNew = false;
public bool IsNew
{
get{return _isNew;}
set{_isNew = value}
}

3) I need to bind the enabled property of a textbox to the negative of
the
value of IsNew. i.e. if IsNew = true, I want the textbox.Enabled =
false and
if IsNew = false, I want textbox.Enabked = true.
Obviously I would like to do this in 1 databinding statement, without
any if
statements. This enables me to set the databinding and forget about
it,
because I'll have the DataSourceUpdat eMode to OnPropertyChang ed.

So this statement,

this.txtPhone1. DataBindings.Ad d("Enabled", this.BindingSou rce,
"IsNew",
true, DataSourceUpdat eMode.OnPropert yChanged);

does the exact reverse of what I need. It sets txtPhone1.Enabl ed =
true if
IsNew = true and vice-versa.

I guess my question is, is there a way to change this statement to set
txtPhone1.Enabl ed = true, if IsNew = false and vice-versa??

Thanks,
Naveen

"Cor Ligthert [MVP]" wrote:
>Naveen,

I assume that the IsNew property has 2 stati.

True and false.

Therefore your binding says when it is false.
("Enabled", this.BindingSou rce, Property , true);
Textbox.Enable d = false;

The IsNew in your binding is only an address, it has no sense to set
that
negative.

Cor
"Naveen" <Na****@discuss ions.microsoft. comschreef in bericht
news:3F******* *************** ************@mi crosoft.com...
>I posted this message to another board and have hardly had any views
on it,
leave alone answers. So I am cross-posting here.

This may be a very simple question but I can't get my head around
it.

I have a textbox's enabled property bound to the IsNew property of
an
object.

this.txtPhone1. DataBindings.Ad d("Enabled", this.BindingSou rce,
"IsNew",
true);

So when the IsNew property is true, my textbox is enabled. This is
correct
behavior.

However, I want to reverse this behavior. In other words, I'd like
to bind
the enabled property to !IsNew, so that the textbox is disabled,
when the
IsNew property is true. How can I do this without creating a new
property
on
the object that returns !IsNew??

Thanks,

Naveen




Dec 10 '06 #4
Hi,

"Naveen" <Na****@discuss ions.microsoft. comwrote in message
news:5B******** *************** ***********@mic rosoft.com...
Cor,
Thanks for your reply. I'm not sure I fully understand your reply.Let me
explain in a little detail.

1) A textbox is bound to an object.

2) The object has an IsNew property.
private bool _isNew = false;
public bool IsNew
{
get{return _isNew;}
set{_isNew = value}
}

3) I need to bind the enabled property of a textbox to the negative of the
value of IsNew. i.e. if IsNew = true, I want the textbox.Enabled = false
and
if IsNew = false, I want textbox.Enabked = true.
Obviously I would like to do this in 1 databinding statement, without any
if
statements. This enables me to set the databinding and forget about it,
because I'll have the DataSourceUpdat eMode to OnPropertyChang ed.

So this statement,

this.txtPhone1. DataBindings.Ad d("Enabled", this.BindingSou rce, "IsNew",
true, DataSourceUpdat eMode.OnPropert yChanged);
You could add an eventhandler for Parse and Format:

Dim bnd As Binding = New Binding("Enable d", this.BindingSou rce, _
"IsNew", True, DataSourceUpdat eMode.OnPropert yChanged)

AddHandler bnd.Parse, AddressOf InverseBool
AddHandler bnd.Format, AddressOf InverseBool

txtPhone1.DataB indings.Add( bnd )

Private Sub InverseBool( sender As Object, e As ConvertEventArg s )
e.Value = Not CBool( e.Value )
End Function
HTH,
Greetings
>
does the exact reverse of what I need. It sets txtPhone1.Enabl ed = true if
IsNew = true and vice-versa.

I guess my question is, is there a way to change this statement to set
txtPhone1.Enabl ed = true, if IsNew = false and vice-versa??

Thanks,
Naveen

"Cor Ligthert [MVP]" wrote:
>Naveen,

I assume that the IsNew property has 2 stati.

True and false.

Therefore your binding says when it is false.
("Enabled", this.BindingSou rce, Property , true);
Textbox.Enable d = false;

The IsNew in your binding is only an address, it has no sense to set that
negative.

Cor
"Naveen" <Na****@discuss ions.microsoft. comschreef in bericht
news:3F******* *************** ************@mi crosoft.com...
>I posted this message to another board and have hardly had any views on
it,
leave alone answers. So I am cross-posting here.

This may be a very simple question but I can't get my head around it.

I have a textbox's enabled property bound to the IsNew property of an
object.

this.txtPhone1. DataBindings.Ad d("Enabled", this.BindingSou rce, "IsNew",
true);

So when the IsNew property is true, my textbox is enabled. This is
correct
behavior.

However, I want to reverse this behavior. In other words, I'd like to
bind
the enabled property to !IsNew, so that the textbox is disabled, when
the
IsNew property is true. How can I do this without creating a new
property
on
the object that returns !IsNew??

Thanks,

Naveen




Dec 10 '06 #5
Bart,

That it is, I was thinking how to do it, but this is of course the answer.

I always forget how handy that binding class is.

Cor

"Bart Mermuys" <bm************ *@hotmail.comsc hreef in bericht
news:H6******** **************@ phobos.telenet-ops.be...
Hi,

"Naveen" <Na****@discuss ions.microsoft. comwrote in message
news:5B******** *************** ***********@mic rosoft.com...
>Cor,
Thanks for your reply. I'm not sure I fully understand your reply.Let me
explain in a little detail.

1) A textbox is bound to an object.

2) The object has an IsNew property.
private bool _isNew = false;
public bool IsNew
{
get{return _isNew;}
set{_isNew = value}
}

3) I need to bind the enabled property of a textbox to the negative of
the
value of IsNew. i.e. if IsNew = true, I want the textbox.Enabled = false
and
if IsNew = false, I want textbox.Enabked = true.
Obviously I would like to do this in 1 databinding statement, without any
if
statements. This enables me to set the databinding and forget about it,
because I'll have the DataSourceUpdat eMode to OnPropertyChang ed.

So this statement,

this.txtPhone1 .DataBindings.A dd("Enabled", this.BindingSou rce, "IsNew",
true, DataSourceUpdat eMode.OnPropert yChanged);

You could add an eventhandler for Parse and Format:

Dim bnd As Binding = New Binding("Enable d", this.BindingSou rce, _
"IsNew", True, DataSourceUpdat eMode.OnPropert yChanged)

AddHandler bnd.Parse, AddressOf InverseBool
AddHandler bnd.Format, AddressOf InverseBool

txtPhone1.DataB indings.Add( bnd )

Private Sub InverseBool( sender As Object, e As ConvertEventArg s )
e.Value = Not CBool( e.Value )
End Function
HTH,
Greetings
>>
does the exact reverse of what I need. It sets txtPhone1.Enabl ed = true
if
IsNew = true and vice-versa.

I guess my question is, is there a way to change this statement to set
txtPhone1.Enab led = true, if IsNew = false and vice-versa??

Thanks,
Naveen

"Cor Ligthert [MVP]" wrote:
>>Naveen,

I assume that the IsNew property has 2 stati.

True and false.

Therefore your binding says when it is false.
("Enabled", this.BindingSou rce, Property , true);
Textbox.Enabl ed = false;

The IsNew in your binding is only an address, it has no sense to set
that
negative.

Cor
"Naveen" <Na****@discuss ions.microsoft. comschreef in bericht
news:3F****** *************** *************@m icrosoft.com...
I posted this message to another board and have hardly had any views on
it,
leave alone answers. So I am cross-posting here.

This may be a very simple question but I can't get my head around it.

I have a textbox's enabled property bound to the IsNew property of an
object.

this.txtPhone1 .DataBindings.A dd("Enabled", this.BindingSou rce,
"IsNew",
true);

So when the IsNew property is true, my textbox is enabled. This is
correct
behavior.

However, I want to reverse this behavior. In other words, I'd like to
bind
the enabled property to !IsNew, so that the textbox is disabled, when
the
IsNew property is true. How can I do this without creating a new
property
on
the object that returns !IsNew??

Thanks,

Naveen




Dec 11 '06 #6
I mean

how handy that binding event.

Cor

"Bart Mermuys" <bm************ *@hotmail.comsc hreef in bericht
news:H6******** **************@ phobos.telenet-ops.be...
Hi,

"Naveen" <Na****@discuss ions.microsoft. comwrote in message
news:5B******** *************** ***********@mic rosoft.com...
>Cor,
Thanks for your reply. I'm not sure I fully understand your reply.Let me
explain in a little detail.

1) A textbox is bound to an object.

2) The object has an IsNew property.
private bool _isNew = false;
public bool IsNew
{
get{return _isNew;}
set{_isNew = value}
}

3) I need to bind the enabled property of a textbox to the negative of
the
value of IsNew. i.e. if IsNew = true, I want the textbox.Enabled = false
and
if IsNew = false, I want textbox.Enabked = true.
Obviously I would like to do this in 1 databinding statement, without any
if
statements. This enables me to set the databinding and forget about it,
because I'll have the DataSourceUpdat eMode to OnPropertyChang ed.

So this statement,

this.txtPhone1 .DataBindings.A dd("Enabled", this.BindingSou rce, "IsNew",
true, DataSourceUpdat eMode.OnPropert yChanged);

You could add an eventhandler for Parse and Format:

Dim bnd As Binding = New Binding("Enable d", this.BindingSou rce, _
"IsNew", True, DataSourceUpdat eMode.OnPropert yChanged)

AddHandler bnd.Parse, AddressOf InverseBool
AddHandler bnd.Format, AddressOf InverseBool

txtPhone1.DataB indings.Add( bnd )

Private Sub InverseBool( sender As Object, e As ConvertEventArg s )
e.Value = Not CBool( e.Value )
End Function
HTH,
Greetings
>>
does the exact reverse of what I need. It sets txtPhone1.Enabl ed = true
if
IsNew = true and vice-versa.

I guess my question is, is there a way to change this statement to set
txtPhone1.Enab led = true, if IsNew = false and vice-versa??

Thanks,
Naveen

"Cor Ligthert [MVP]" wrote:
>>Naveen,

I assume that the IsNew property has 2 stati.

True and false.

Therefore your binding says when it is false.
("Enabled", this.BindingSou rce, Property , true);
Textbox.Enabl ed = false;

The IsNew in your binding is only an address, it has no sense to set
that
negative.

Cor
"Naveen" <Na****@discuss ions.microsoft. comschreef in bericht
news:3F****** *************** *************@m icrosoft.com...
I posted this message to another board and have hardly had any views on
it,
leave alone answers. So I am cross-posting here.

This may be a very simple question but I can't get my head around it.

I have a textbox's enabled property bound to the IsNew property of an
object.

this.txtPhone1 .DataBindings.A dd("Enabled", this.BindingSou rce,
"IsNew",
true);

So when the IsNew property is true, my textbox is enabled. This is
correct
behavior.

However, I want to reverse this behavior. In other words, I'd like to
bind
the enabled property to !IsNew, so that the textbox is disabled, when
the
IsNew property is true. How can I do this without creating a new
property
on
the object that returns !IsNew??

Thanks,

Naveen




Dec 11 '06 #7
Works great. Thanks a lot.

"Bart Mermuys" wrote:
Hi,

"Naveen" <Na****@discuss ions.microsoft. comwrote in message
news:5B******** *************** ***********@mic rosoft.com...
Cor,
Thanks for your reply. I'm not sure I fully understand your reply.Let me
explain in a little detail.

1) A textbox is bound to an object.

2) The object has an IsNew property.
private bool _isNew = false;
public bool IsNew
{
get{return _isNew;}
set{_isNew = value}
}

3) I need to bind the enabled property of a textbox to the negative of the
value of IsNew. i.e. if IsNew = true, I want the textbox.Enabled = false
and
if IsNew = false, I want textbox.Enabked = true.
Obviously I would like to do this in 1 databinding statement, without any
if
statements. This enables me to set the databinding and forget about it,
because I'll have the DataSourceUpdat eMode to OnPropertyChang ed.

So this statement,

this.txtPhone1. DataBindings.Ad d("Enabled", this.BindingSou rce, "IsNew",
true, DataSourceUpdat eMode.OnPropert yChanged);

You could add an eventhandler for Parse and Format:

Dim bnd As Binding = New Binding("Enable d", this.BindingSou rce, _
"IsNew", True, DataSourceUpdat eMode.OnPropert yChanged)

AddHandler bnd.Parse, AddressOf InverseBool
AddHandler bnd.Format, AddressOf InverseBool

txtPhone1.DataB indings.Add( bnd )

Private Sub InverseBool( sender As Object, e As ConvertEventArg s )
e.Value = Not CBool( e.Value )
End Function
HTH,
Greetings

does the exact reverse of what I need. It sets txtPhone1.Enabl ed = true if
IsNew = true and vice-versa.

I guess my question is, is there a way to change this statement to set
txtPhone1.Enabl ed = true, if IsNew = false and vice-versa??

Thanks,
Naveen

"Cor Ligthert [MVP]" wrote:
Naveen,

I assume that the IsNew property has 2 stati.

True and false.

Therefore your binding says when it is false.
("Enabled", this.BindingSou rce, Property , true);
Textbox.Enabled = false;

The IsNew in your binding is only an address, it has no sense to set that
negative.

Cor
"Naveen" <Na****@discuss ions.microsoft. comschreef in bericht
news:3F******** *************** ***********@mic rosoft.com...
I posted this message to another board and have hardly had any views on
it,
leave alone answers. So I am cross-posting here.

This may be a very simple question but I can't get my head around it.

I have a textbox's enabled property bound to the IsNew property of an
object.

this.txtPhone1. DataBindings.Ad d("Enabled", this.BindingSou rce, "IsNew",
true);

So when the IsNew property is true, my textbox is enabled. This is
correct
behavior.

However, I want to reverse this behavior. In other words, I'd like to
bind
the enabled property to !IsNew, so that the textbox is disabled, when
the
IsNew property is true. How can I do this without creating a new
property
on
the object that returns !IsNew??

Thanks,

Naveen




Dec 12 '06 #8

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

Similar topics

16
5092
by: JKop | last post by:
Take a class like the following: class Finger { public: double length; }
9
3975
by: Guy | last post by:
I have extended the datetimepicker control to incorporate a ReadOnly property. I have used the new keyword to implement my own version of the value property, so that if readonly == true then it will not set the value of the control and will leave the checked status of the checkbox to false when a user selects a new date. this works fine when using the control on a win2k machine but if we use it on a win XP box and call
2
3870
by: Richard | last post by:
Hi, I have a DateTime picker control on a form. The datetime picker control is data bound to a column in a DataTable. Yes I know about bound DateTime pickers and DBNull and etc. so no troubles with that stuff... However, as somebody out there probably knows, programmatically setting the DateTimePicker.Value property to a new VALUE does NOT in itself constitute a CHANGE to
3
3160
by: Kevin Swanson | last post by:
I'm writing what should be a very simple app against an Oracle database. The app has a number of user controls, any one of which is loaded into a main display page using the loadControl method, depending on which menu item a user selects. Each of these controls follows the same basic pattern: Get a dataset from the database and then display the results using basic databinding. Everything works fine except that I'll occaisionally get an...
0
3226
by: Steve | last post by:
I'm trying to implement databinding on a composite control and I'm getting an error with the data when I change the DataSource. The first time I set the DataSource and call DataBind() everything works fine, but when I set the DataSource to a new value (DataTable) and then call DataBind again, I get some strange results from the command events of some embedded ImageButton controls... althought the data appears to be displayed correctly, the...
8
2185
by: GaryDean | last post by:
We have been noticing that questions on vs.2005/2.0 don't appear to get much in answers so I'm reposting some questions posted by some of the programmers here in our organization that never got answered... In 1.1 we always did our own myDataAdapter.fills and we liked that control for lots of good reasons. Now the new DataSource (or is it a TableAdapter:Dataset) automatically fills the Gridview. How can we control that fill? In a...
5
12530
by: Mark R. Dawson | last post by:
Hi all, I may be missing something with how databinding works but I have bound a datasource to a control and everything is great, the control updates to reflect the state of my datasource when I update the datasource - awesome, but I have an issue with updating from a different thread. Here is my datasource, a person class that raises the PropertyChanged event: class Person : INotifyPropertyChanged {
1
14314
by: CorporateCoder | last post by:
Hi, I am trying to bind the selected value of a databound dropdown box in a databound gridview control to the value being displayed in the template column the dropdown box has been added to. Both the grid and the dropdown box are retrieving and displaying data fine, I just cant bind the two together. I followed the instructions in the help document called 'Walkthrough: Displaying a Drop-Down List While Editing in the GridView Web...
3
1886
by: Peter | last post by:
Hi! I am having some very strange behavior with my databound controls. It's taken a long time to isolate exactly what is provoking the problem, but I'm still leagues away from solving it. I have a DataView which filters a DataSet. Bound to this dataview is a ListBox, via its DataSource property. The DisplayMember is the name property of the row. Simple enough so far?
0
9591
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10053
jinu1996
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...
0
9867
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 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...
1
7415
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6676
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();...
0
5312
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3573
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2816
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.