filter bool values - InfoPath Dev
in

InfoPath Dev

filter bool values

Last post 01-20-2009 01:27 AM by tylkomat. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 01-19-2009 02:55 AM

    filter bool values

    Hello folks,

    I have a repeating table with checkboxes and a repeating folder with values to update. When I select a checkbox, I want to set all check fields which have the same article number as the one which depend on the checkbox to the value of the selected checkbox. I tried to set a rule with a filter but an error appears, that I cannot set a filter to that field.

    Is it not possible to filter boolean values ? How can I archive it ?

    CAML:

    <myFields>
     <Bestellungen>
      <Bestellung> (repeating)
       <Artikelnummer>
       <Beschreibung>
       <Menge>
       <check> (checkbox value)
      </Bestellung>
     </Bestellungen>

     <Updates>
      <Update>
       <ID>
       <uCheck> (bool to set when checkbox is selected)
       <uArtikelnummer> (should match Artikelnummer)
      </Update>
     </Updates>
    </myFields>

    Thanks in advance.

     Regards Matthias.

     PS: I hope my explanation is understandable.

  • 01-19-2009 08:14 PM In reply to

    Hi,

    You can achieve this using the following code. Write an on after change event for the check box.

    [InfoPathEventHandler(MatchPath = "/my:myFields/my: Bestellungen/my: Bestellung/my: check", EventType = InfoPathEventType.OnAfterChange)]

    public void field29_OnAfterChange(DataDOMEvent e)

    {

    if (e.IsUndoRedo)

    {               

     return;

    }

     

    if (e.Site.text == "true")

    {

     string Artikelnummer = e.Site.parentNode.selectSingleNode("my: Artikelnummer").text;

     IXMLDOMNodeList uCheckNodes = thisXDocument.DOM.selectNodes(string.Format("/my:myFields/my: Updates/my: Update [my: uArtikelnummer = '{0}']/my: uCheck", Artikelnummer));

     foreach (IXMLDOMNode uCheckNode in uCheckNodes)

     {

       setNodeValue(uCheckNode, true);

     }

    }

    }

     

     

    private void setNodeValue(IXMLDOMNode node, object newValue)

            {

                if (node == null || newValue == null)

                    return;

     

                string value = Convert.ToString(newValue, CultureInfo.InvariantCulture);

     

                // The xsi:nil needs to be removed before we set the value.

                if ((node.nodeType != DOMNodeType.NODE_ATTRIBUTE) && (value.Length != 0))

                {

                    IXMLDOMElement elementNode = node as IXMLDOMElement;

                    if ((elementNode != null) && (elementNode.getAttribute("xsi:nil") != null))

                    {

                        elementNode.removeAttribute("xsi:nil");

                    }

                }

     

                // Force boolean values to lowercase.

                if (newValue.GetType() == Type.GetType("System.Boolean"))

                    value = value.ToLower(cultureInfo);

     

                // Setting the value would mark the document as dirty.

                // Let's do that if the value has really changed.

                if (String.Compare(node.text, value) != 0)

                    node.text = value;

            }

     

    Swathip
    www.ggktech.com
  • 01-19-2009 11:58 PM In reply to

    Thanks a lot. That brought me to the right idea. I think I found a little shorter way, but with the same basic principle.

  • 01-20-2009 01:27 AM In reply to

    For those who want to know how I did it. Here my solution.

     I added a changeListener through context click on the checkbox->programming->change event.

    My Code to this event looks like the following:

    public void check_Changed(object sender, XmlEventArgs e)

    {

    // Write your code here to change the main data source.

    if (e.Operation.ToString() == "ValueChange")

    {

    String Artikelnummer = e.Site.SelectSingleNode("../my:Artikelnummer", NamespaceManager).Value;

    XPathNavigator xnUArtikelnummer = this.DataSources[0].CreateNavigator().SelectSingleNode("/my:myFields/my:Updates", NamespaceManager);

    foreach(XPathNavigator Node in xnUArtikelnummer.Select("//my:Update", NamespaceManager))

    {

    if (Artikelnummer == Node.SelectSingleNode("./my:uArtikelnummer", NamespaceManager).InnerXml)

    {

    Node.SelectSingleNode(
    "./my:uCheck", NamespaceManager).InnerXml = e.NewValue;

    }

    }

    }

    }

     

    Comment:

    - look if the operation on the checkbox was a changeEvent

    - compare Artikelnummer and uArtikelnummer

    - if both are equal change the uCheck value to the current value of the checkbox

     

    PS: Will it be faster if I just select all equal Artikelnummer and uArtikelnummer via XPath expression ? And only iterate trough them instead of all values?

Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.