I think you might be getting confused on something... text boxes do not hold data, they just provide access to the data.
So if you have 3 different text boxes in 3 different views, but each one is bound to the same data source... then when you update one "text box" you are really updating all 3 of them.
If you want each text box to hold different data, then each one needs to bound to a different data field.
Hope this helps!

Signature
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com
Hi there,
I have a form with a field that concats lots of text together.
this field is contained within text boxes on three views of the form, and
each view needs a different function to make this concat.
I've tried using the famous 'fx' button however, this seems to set the
formula for the field, not the text-box, as such, when I change view and set
the formula for that view, it changes all three formulas.
So, I've tried to do this using script (the field is called "notes"):
public void OnSwitchView(DocEvent e)
{
// grab notes node
IXMLDOMNode nodeNote =
thisXDocument.DOM.selectSingleNode("/my:myFields/my:richiesta/my:note")
// look which form we are on, and set the default value formula
switch (thisXDocument.View.Name.ToString()) {
case "ferie":
thisXDocument.UI.Alert("ferie");
// set string for default formula
strDefaultFormula="concat("hello","world")
break;
case "permesso":
thisXDocument.UI.Alert("permesso");
// set string for default formula
strDefaultFormula="concat("hello","world")
break;
case "malattia":
thisXDocument.UI.Alert("malattia");
// set string for default formula
strDefaultFormula="concat("hello","world")
break;
default:
thisXDocument.UI.Alert("case crashed out.");
break;
}
nodeNote.something.somethingelse= strDefaultFormula
}
I am having difficulty finding which property of nodeNote I need to change.
As there doens't seem to be any reference to this on the web, perhaps it
can't be changed, and in that case, how do I do such a thing?
thanks again,
nick
nick brandwood - 01 Mar 2005 08:49 GMT
hello greg,
thanks for your reply.
I think you've not understood my question.
I have a form with three views, each for a particular case of the form.
Within those three views is a textbox that must compile a phrase based on
the information compiled in the form. The phrase that is gramatically
different based on which view you are using. A user would not use all three
views, but would choose the view based on the requirements at the time.
(Sick, Approved Absence or Holiday)
As you state, the textbox is indeed linked to the data, not the view and as
such, even though a text box exists on three different views, it only has one
default value function.
I was looking for a method to change the default value function based on
which view is opened, thereby faking an equation for each view. As you can
see from the code below, however I couldn't find a property or method on the
node object that allows me to define the default value function.
> nodeNote.something.somethingelse = strDefaultFormula
It it not possible to change this equation at run time?
I do not want to create three different text boxes, as data should be
contained within the same XML element.
thanks again for your quick reply...
nick
> public void OnSwitchView(DocEvent e)
> {
[quoted text clipped - 35 lines]
>
> nick
Greg Collins [InfoPath MVP] - 01 Mar 2005 17:30 GMT
Okay... that being the case, I think you are doing the correct thing by using an OnSwitchView event handler. That is the only way to do what you want to do.
The assignment property you are looking for is ".text" or ".nodeValue":
nodeNote.text = strDefaultFormula

Signature
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com
hello greg,
thanks for your reply.
I think you've not understood my question.
I have a form with three views, each for a particular case of the form.
Within those three views is a textbox that must compile a phrase based on
the information compiled in the form. The phrase that is gramatically
different based on which view you are using. A user would not use all three
views, but would choose the view based on the requirements at the time.
(Sick, Approved Absence or Holiday)
As you state, the textbox is indeed linked to the data, not the view and as
such, even though a text box exists on three different views, it only has one
default value function.
I was looking for a method to change the default value function based on
which view is opened, thereby faking an equation for each view. As you can
see from the code below, however I couldn't find a property or method on the
node object that allows me to define the default value function.
> nodeNote.something.somethingelse = strDefaultFormula
It it not possible to change this equation at run time?
I do not want to create three different text boxes, as data should be
contained within the same XML element.
thanks again for your quick reply...
nick
> public void OnSwitchView(DocEvent e)
> {
[quoted text clipped - 35 lines]
>
> nick
nick brandwood - 02 Mar 2005 08:57 GMT
...so the default value equation is set by giving as the value...?
ok, will give it a try.
thanks
> Okay... that being the case, I think you are doing the correct thing by using an OnSwitchView event handler. That is the only way to do what you want to do.
>
[quoted text clipped - 75 lines]
> >
> > nick
Greg Collins [InfoPath MVP] - 02 Mar 2005 18:40 GMT
Oh, I'm beginning to see the light of what you are asking... My appologies for taking so long.
So if I understand correctly, you do not want to set the value of the field, you want to change the "default value" which is an equation that is used to set the value.
This, however is not possible in the current release of InfoPath. I'm not sure it is something that has been considered for the next release either.
If this is really what you want, then you will need to use OnAfterChange events on the fields referred to in your equations and perform your calculation in code.
I will forward the idea to Microsoft, though I'm sure they will pick up this posting as well.

Signature
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com
...so the default value equation is set by giving as the value...?
ok, will give it a try.
thanks
"Greg Collins [InfoPath MVP]" wrote:
> Okay... that being the case, I think you are doing the correct thing by using an OnSwitchView event handler. That is the only way to do what you want to do.
>
[quoted text clipped - 52 lines]
> >
> > nick