Infopath重复表中显示row number 并读取

 http://office.microsoft.com/en-us/infopath-help/display-the-row-number-in-a-repeating-table-HP001042602.aspx

 

You can use expression boxes to display the row number in a repeating table, as well as perform other calculations. When you create formulas in an expression box, you refer to the fields and groups to which controls on the form are bound, rather than the controls themselves. The formulas are created using XPath, but you can follow these steps without knowing XPath.

  1. In design mode, place the insertion point where you want to insert the expression box.

 NOTE   The expression box must be part of the repeating table.

  1. If the Controls task pane is not visible, click More Controls on the Insertmenu.
  2. In the Controls task pane, click Expression Box.
  3. In the Insert Expression Box dialog box, type position() in the XPath box.
  4. To test the formula, click Preview Form on the Standard toolbar.



Autonumbering fields in a repeating table in InfoPath 2007 using VB.NET code

 

Note that you are not required to write code if you want to create sequential numbers in a repeating table, and that you could also use a formula to autonumber a repeating table in InfoPath.

Here are the steps:

  1. Follow the instructions in Programmatically execute code when a repeating table row is inserted or deleted to add a Changed event handler for the row of a repeating table.
  2. Add the following code to the Changed event: Dim nav As XPathNavigator = MainDataSource.CreateNavigator()
    Dim iter As XPathNodeIterator = nav.Select("//my:field1", NamespaceManager) 
    Dim i As Integer = 1 
    While iter.MoveNext() 
    iter.Current.SetValue(i.ToString()) 
    i = i + 1 
    End While


    where my:field1 is a field in the repeating table.

The final code would look something like:

Public Sub group2_Changed(ByVal sender As Object, ByVal e As XmlEventArgs) 
Dim nav As XPathNavigator = MainDataSource.CreateNavigator() 
Dim iter As XPathNodeIterator = nav.Select("//my:field1", NamespaceManager) 
Dim i As Integer = 1 
While iter.MoveNext() 
iter.Current.SetValue(i.ToString()) 
i = i + 1 
End While 
End Sub


Now whenever you insert a row into the repeating table or delete a row from the repeating table, the my:field1 fields in all of the rows of the repeating table are automatically renumbered




http://www.bizsupportonline.net/infopath2007/how-to-get-current-row-number-repeating-table-infopath-vbnet-code.htm

Example: In InfoPath, you have a repeating table with 3 columns. You stored the row numbers in the first field (my:field1) of the repeating table. When you change the value of the second field (my:field2) of the repeating table and then move away from that field, you want to determine the number of the row in which you just made a change.

You can write the following code for the Changed event handler ofmy:field2 to determine the row number as follows:

 

 

Public Sub field2_Changed(ByVal sender As Object, ByVal e As XmlEventArgs) 
Dim site As XPathNavigator = e.Site 
site.MoveToParent() 
Dim rowNumber As String = site.SelectSingleNode("my:field1", NamespaceManager).Value 
End Sub


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值