Fixed! (Zip file has the small Questions MDB and the Template, MDB was just for ease of working locally)
Some general mindsifts I had to make
1. If I am in total control (through code) of the radio buttons I only ever need to make two changes i.e. 1. set the new choice to "true", 2. find the old "true" choice and set that to "false". This applies whether I have 4 or 400 buttons in a "only one answer " scenario.
2. I discovered that on the change event the first change is implicit i.e. 1. set new choice to true is done by virtue of clicking on the option
So I used XPathNodeIterator to go through the rest of the options in my case grouped by ParentQuestionID excluding the current item (because I want that to stay true) find the other true option and set it to false.
To avoid the infinite loop problem I use a field on the MainDataSource to be either 0 or 1. The value is 0 by default and I change it to 1 just before changing the selected field to false (which results in the changed event firing again)
In the code I check to see if the value is 0 do the changes if the value is 1 do nothing but set the field back to 0. I have included the code below. It's not pretty but it works.
MCTemplate1.zip
public void InternalStartup()
{
EventManager.XmlEvents["/dfs:myFields/dfs:dataFields/d:MCQuestionQuery/d:MCOptionsQuery/@Selected", "MCQuestionQuery"].Changed += new XmlChangedEventHandler(MCQuestionQuery__Selected_attr_Changed);
}
public void MCQuestionQuery__Selected_attr_Changed(object sender, XmlEventArgs e)
{
string _checkStateField = String.Empty;
string _qIDFilter = String.Empty;string _mcIDFilterToTrue = String.Empty;
string _mcIDFilterToFalse = String.Empty;string _checkNode = String.Empty;
XPathNavigator mainroot = this.MainDataSource.CreateNavigator();XPathNavigator root = this.DataSources["MCQuestionQuery"].CreateNavigator();
//setup all the variables
_qIDFilter = e.Site.SelectSingleNode(
"../@QuestionID").ToString(); //The specific question ID
_mcIDFilterToTrue = e.Site.SelectSingleNode(
"../@MCID").ToString(); //The specific Multiple Choice ID
_checkStateField = mainroot.SelectSingleNode(
"/my:myFields/my:CheckOptions/my:checkStateField", NamespaceManager).ToString(); // the check state field value
//Check if field is zero then this is the first time the change has been activated
try
{
if (_checkStateField == "0")
{
//Find all values that match this Question ID data setXPathNodeIterator findTrueValues = root.Select("/dfs:myFields/dfs:dataFields/d:MCQuestionQuery/d:MCOptionsQuery/@MCID[../@QuestionID=" + _qIDFilter + "]", NamespaceManager);
_checkNode = findTrueValues.Count.ToString();
//MessageBox.Show("There are " + _checkNode + " values");while (findTrueValues.MoveNext())
{
if (findTrueValues.Current.Value != _mcIDFilterToTrue)
{
_mcIDFilterToFalse = findTrueValues.Current.Value;
//MessageBox.Show("The current MCID Value is: " + _mcIDFilterToFalse);_checkNode = findTrueValues.Current.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:MCQuestionQuery/d:MCOptionsQuery/@Selected[../@MCID =" + _mcIDFilterToFalse +"]",NamespaceManager).ToString();if (_checkNode == "True")
{
mainroot.SelectSingleNode(
"/my:myFields/my:CheckOptions/my:checkStateField", NamespaceManager).SetValue("1");findTrueValues.Current.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:MCQuestionQuery/d:MCOptionsQuery/@Selected[../@MCID =" + _mcIDFilterToFalse + "]", NamespaceManager).SetValue("False");
}
//MessageBox.Show("This fields selected value is" + _checkNode);
}
}
}
else if (_checkStateField == "1")
{
mainroot.SelectSingleNode("/my:myFields/my:CheckOptions/my:checkStateField", NamespaceManager).SetValue("0");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
P.S. Thanks for the help Clay, not sure whether you were offering or selling the webservices, either way let me know what you were referring to. I have a dev team that are working on all of that at the moment. I dont usually dabble with code but they told me this couldnt be done...... whatever!