Auto-Insert New Rows In Repeating Table based on value selected from a drop-down list box - InfoPath Dev
in

InfoPath Dev

Auto-Insert New Rows In Repeating Table based on value selected from a drop-down list box

Last post 11-18-2009 12:51 PM by [email protected]. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 11-12-2009 03:07 PM

    Auto-Insert New Rows In Repeating Table based on value selected from a drop-down list box

    Hello all,

    Just wondering if it's posible to code this in c#

    I've a form with 1 repeating table, inside there're 4 fields with field1 & field2 as drop-down list box, field 3 is text box, & field 4 is option button.

    I want to be able to change the value in field1 & it'll auto insert the number of row(s) depand on the value in field1 is being selected.

    Would this be possible to code?

    If yes, please show me how.

    Here is the code that I wish someone would be able to help me with this change event:

    public void Field1_Changed(object sender, XmlEventArgs e)

    {

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

     

    /*

    * if field1 = Field1Value1, set field2 = Field2Value1

    * if field1 = Field2Value2, auto-insert 1 row, set 1st row of field2 = Field2Value1, & 2nd row of field2 = Field2Value2

    * if field1 = Field3Value3, auto-insert 2 rows, set 1st row of field2 = Field2Value1, & 2nd row of field2 = Field2Value2, & 3rd row of field2 = Field2Value3

    * if field1 = Field3Value4, auto-insert 3 rows, set 1st row of field2 = Field2Value1, & 2nd row of field2 = Field2Value2, & 3rd row of field2 = Field2Value3, & 4th row of field2 = Field2Value4

    */

    }

  • 11-15-2009 04:21 AM In reply to

    Re: Auto-Insert New Rows In Repeating Table based on value selected from a drop-down list box

    Just download a free version of qRules 1.8 from Qdabra.com's site and you can do it without code.

    Patrick Halstead
    Project Manager at Qdabra
  • 11-16-2009 06:37 AM In reply to

    Re: Auto-Insert New Rows In Repeating Table based on value selected from a drop-down list box

    Hello Patrick,

    Thank you very much for you suggestion, but I'm more interest in looking for how to code them in C#.

    Would you happen to have any good advice?

    Thanks!

    JH

  • 11-18-2009 12:51 PM In reply to

    Re: Auto-Insert New Rows In Repeating Table based on value selected from a drop-down list box

    Hello all,

    Just wondering if someone can help me please!

    I've a form with 1 repeating table, inside there're 4 fields with field1 as drop-down list box, field 2, field 3 is text box, & field 4 is option button.

    I want to be able to change the value in field1 & it'll auto insert the number of row(s) depand on the value in field1 is being selected, then auto-fill in the string array value in field2 depand on the value in field1 is being selected.

    I've done the adding & deleting row(s), but i'm having trouble setting the value(s) into field2 from a string array depand on what field1 is being selected.

    Please help me, I've attached the file & here is the code that I wish someone would be able to help me with this change event:

    public void Field1_Changed(object sender, XmlEventArgs e)

    {

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

     

    XPathNavigator root = MainDataSource.CreateNavigator();

    string value = root.SelectSingleNode("/my:myFields/my:Field1", NamespaceManager).Value;

    XPathNodeIterator iter = null;

    XPathNavigator first = null;

    XPathNavigator last = null;

    // if field1 = Field1Value1, set field2 = F2V1

    if (value == "Field1Value1")

    {

    iter = root.Select(
    "/my:myFields/my:myGroup", NamespaceManager);if (iter.Count.ToString() != null)

    {

    first = root.SelectSingleNode("/my:myFields/my:myGroup[1]", NamespaceManager);

    last = root.SelectSingleNode("/my:myFields/my:myGroup[last()]", NamespaceManager);

    first.DeleteRange(last);

    CurrentView.ExecuteAction(
    ActionType.XCollectionInsert, "myGroup_21");root.SelectSingleNode("/my:myFields/my:myGroup/my:Field2", NamespaceManager).SetValue("F2V1");

    }

    }

    // if field1 = Field1Value2, auto-insert 1 row.

    // set 1st row of field2 = F2V1. [not working for setting value]

    // set 2nd row of field2 = F2V2. [not working for setting value]

    if (value == "Field1Value2")

    {

    iter = root.Select(
    "/my:myFields/my:myGroup", NamespaceManager);

    int nRow = 1;

    string[] f2v = { "", "F2V1", "F2V2" };if (iter.Count.ToString() != null)

    {

    first = root.SelectSingleNode("/my:myFields/my:myGroup[1]", NamespaceManager);

    last = root.SelectSingleNode("/my:myFields/my:myGroup[" + iter.Count.ToString() + "]", NamespaceManager);

    first.DeleteRange(last);

    while (nRow < 3)

    {

    CurrentView.ExecuteAction(
    ActionType.XCollectionInsert, "myGroup_21");root.SelectSingleNode("/my:myFields/my:myGroup/my:Field2", NamespaceManager).SetValue(f2v[nRow]);

    nRow++;

    }

    }

    }

    // if field1 = Field1Value3, auto-insert 2 rows.

    // set 1st row of field2 = F2V1. [not working for setting value]

    // set 2nd row of field2 = F2V2. [not working for setting value]

    // set 3rd row of field2 = F2V3. [not working for setting value]

    if (value == "Field1Value3")

    {

    iter = root.Select(
    "/my:myFields/my:myGroup", NamespaceManager);

    int nRow = 1;

    string[] f2v = { "", "F2V1", "F2V2", "F2V3" };if (iter.Count.ToString() != null)

    {

    first = root.SelectSingleNode("/my:myFields/my:myGroup[1]", NamespaceManager);

    last = root.SelectSingleNode("/my:myFields/my:myGroup[" + iter.Count.ToString() + "]", NamespaceManager);

    first.DeleteRange(last);

    while (nRow < 4)

    {

    CurrentView.ExecuteAction(
    ActionType.XCollectionInsert, "myGroup_21");root.SelectSingleNode("/my:myFields/my:myGroup/my:Field2", NamespaceManager).SetValue(f2v[nRow]);

    nRow++;

    }

    }

    }

    // if field1 = Field1Value4, auto-insert 3 rows.

    // set 1st row of field2 = F2V1. [not working for setting value]

    // set 2nd row of field2 = F2V2. [not working for setting value]

    // set 3rd row of field2 = F2V3. [not working for setting value]

    // set 4th row of field2 = F2V4. [not working for setting value]

    if (value == "Field1Value4")

    {

    iter = root.Select(
    "/my:myFields/my:myGroup", NamespaceManager);

    int nRow = 1;

    string[] f2v = { "", "F2V1", "F2V2", "F2V3", "F2V4" };if (iter.Count.ToString() != null)

    {

    first = root.SelectSingleNode("/my:myFields/my:myGroup[1]", NamespaceManager);

    last = root.SelectSingleNode("/my:myFields/my:myGroup[" + iter.Count.ToString() + "]", NamespaceManager);

    first.DeleteRange(last);

    while (nRow < 5)

    {

    CurrentView.ExecuteAction(
    ActionType.XCollectionInsert, "myGroup_21");root.SelectSingleNode("/my:myFields/my:myGroup/my:Field2", NamespaceManager).SetValue(f2v[nRow]);

    nRow++;

    }

    }

    }

    // if field1 = Field1Value5, auto-insert 4 rows.

    // set 1st row of field2 = F2V1. [not working for setting value]

    // set 2nd row of field2 = F2V2. [not working for setting value]

    // set 3rd row of field2 = F2V3. [not working for setting value]

    // set 4th row of field2 = F2V4. [not working for setting value]

    // set 5th row of field2 = F2V5. [not working for setting value]

    if (value == "Field1Value5")

    {

    iter = root.Select(
    "/my:myFields/my:myGroup", NamespaceManager);

    int nRow = 1;

    string[] f2v = { "", "F2V1", "F2V2", "F2V3", "F2V4", "F2V5" };if (iter.Count.ToString() != null)

    {

    first = root.SelectSingleNode("/my:myFields/my:myGroup[1]", NamespaceManager);

    last = root.SelectSingleNode("/my:myFields/my:myGroup[" + iter.Count.ToString() + "]", NamespaceManager);

    first.DeleteRange(last);

    while (nRow < 6)

    {

    CurrentView.ExecuteAction(
    ActionType.XCollectionInsert, "myGroup_21");root.SelectSingleNode("/my:myFields/my:myGroup/my:Field2", NamespaceManager).SetValue(f2v[nRow]);

    nRow++;

    }

    }

    }

    // if field1 = Field1Value6, auto-insert 5 rows.

    // set 1st row of field2 = F2V1. [not working for setting value]

    // set 2nd row of field2 = F2V2. [not working for setting value]

    // set 3rd row of field2 = F2V3. [not working for setting value]

    // set 4th row of field2 = F2V4. [not working for setting value]

    // set 5th row of field2 = F2V5. [not working for setting value]

    // set 6th row of field2 = F2V6. [not working for setting value]

    if (value == "Field1Value6")

    {

    iter = root.Select(
    "/my:myFields/my:myGroup", NamespaceManager);

    int nRow = 1;

    string[] f2v = { "", "F2V1", "F2V2", "F2V3", "F2V4", "F2V5", "F2V6" };if (iter.Count.ToString() != null)

    {

    first = root.SelectSingleNode("/my:myFields/my:myGroup[1]", NamespaceManager);

    last = root.SelectSingleNode("/my:myFields/my:myGroup[" + iter.Count.ToString() + "]", NamespaceManager);

    first.DeleteRange(last);

    while (nRow < 7)

    {

    CurrentView.ExecuteAction(
    ActionType.XCollectionInsert, "myGroup_21");root.SelectSingleNode("/my:myFields/my:myGroup/my:Field2", NamespaceManager).SetValue(f2v[nRow]);

    nRow++;

    }

    }

    }

    }

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