Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / General MS InfoPath Questions / June 2005

Tip: Looking for answers? Try searching our database.

How to get row position in a secondary source with VB.Net

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
kfrost - 20 Jun 2005 20:39 GMT
Hello,

I have a page with a repeating table on it that populates with records from
a SQL database on load.  Users click on a record for more detail about it.  
I'm trying to figure out how to get the row position value with VB.Net.  I
know you can use the position () in a rule but I need to store this value in
a global variable for later use and I'm using VB.Net.

If anybody can post a simple example of how to do this I would greatly
appreciate it.

Thanks.

kris
Scott L. Heim [MSFT] - 20 Jun 2005 22:24 GMT
Hi Kris,

May I ask why you would need the position? The reason I ask is that if you
add a column to your repeating table and place a button and place a button
in that column you can get the current record information by using this
code on the Click event:

    thisXDocument.UI.Alert(e.Source.xml)

Then, if you wanted to get a specific field value, you could use code like
this:

    thisXDocument.UI.Alert(e.Source.selectSingleNode("@ShipperID").text)

I hope this helps; however, please accept my apologies if this was a waste
of information for you! :-)

Best regards,

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights
kfrost - 20 Jun 2005 22:51 GMT
Hello Scott,

First of all thank you for the response for me right now with Infopath any
info I get is good info.  :)

I'm trying to create a type of master/detail type scenario.  The thing is
though that the master is in one view and the table is populated by a
secondary source.  I do have a button in the repeating table and when clicked
I take the TripID value from the secondary data source and set it to a query
value in my Main data source which is a connected to SQL.

I've posted and posted for over a week trying to figure out a Xpath syntax
to do this.  However, I figure it would be better to just do it with code.  
If nothing else a good learning experience for me.

So I want to take the row position and use a global variable to store it to
use with |< << >> >| buttons on the detail page to allow users to traverse
through records.

So I want to try and do this by storing the row position of a record
selected.  Then if a user clicks a next or previous button, I increment or
decrement the row position accordingly.

I'll step through the e.source.xml you pointed out and see if I can find
what I need in there but I hope that gives you a better idea of what I'm
trying to do.  Any additional info as always would be greatly appreciated.

Again thanks for your post.

P.S. I know if there was some way to create a secondary data source like you
can if your form isn't based off a database connection you could use a rule
to populate a field in a data source.  But this isn't that easily done when
you are using a template to a database connection.  I suppose you could
create an XML file to do it but I'd prefer not to have too.

> Hi Kris,
>
[quoted text clipped - 19 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights
kfrost - 21 Jun 2005 02:22 GMT
Hello Scott,

I don't see a way to get the row position from the XML you specified below.  
How would you go about doing that?

> Hello Scott,
>
[quoted text clipped - 54 lines]
> >
> > This posting is provided "AS IS" with no warranties, and confers no rights
Scott L. Heim [MSFT] - 21 Jun 2005 13:23 GMT
Hi Kris,

As I had mentioned, this would not provide the actual "position" but could
provide you information concerning the current row you are on. For
instance, if you were trying to identify an "ID" field's value from the
current row you are on, this method would provide that type of data but not
the actual position of the row.

This is why I had asked if you truly need the position or possibly just
specific information regarding a field in the current row you are on.

Is it truly the position you need?

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights
kfrost - 21 Jun 2005 13:55 GMT
Thank you Scott, yes I need the position?  

I need the position because I take the tripID value from this secondary data
source called Trips.  I use that value to set the /dfs:queryFields/d:tripID
value in my Main data source.  

So when a user for example clicks on the >> button.  In order to display the
next record, I need to code to get the TripID value from the next record from
the Trips secondary data source and then change the /dfs:queryFields/q:tripID
in the Main Data Connection to that value and then re run the Main query to
get that records info.

Maybe this will shed more light.  

Views:
Main
TripDetails

Data Sources
Main (Default) (This is the database connection to SQL the form was built
off of)
Trips (Secondary) This populates the Repeating table on the main View from a
table in SQL called Trips.

The repeating table in Main does have a button that when clicked kicks off a
rule named Query.

Query has 3 actions:
1) Sets field value of /dfs:Main/dfs:queryFields/q:Trips/@TripID to
xdXDocument:GetDOM("Trips")/dfs:myFields/dfs:dataFields/d:Trips/@TripID
2)Query using a Data connection: Main
3) Switch to View: TripDetails

All this works fine.  Now I'm trying to add functionality to where if a user
wants to go to the next, previous, first or Last record they click on a
corresponding button such as |< << >> >|

So say they click on the next button in the tripDetails view, I need to
access the TripsDetail Data Connection which was kicked off by the Main view.
I need to then get the TripID value from the next record in the xml "Data
Set" so I can then set the TripID of the Main Query TripID field and re run
the query.

So that's why I need the Row position.  When a user first clicks on a record
in the main view to get the details of the selection, I'm going to populate a
global variable with the row position.  When they click next, I will then
increment this variable by one.  Then try to figure out the VB.Net code
equivalent that will give me the same functionality of this XPath statement
which works when set in a rule.

xdXDocument:GetDOM("Trips")/dfs:myFields/dfs:dataFields/d:Trips[position() =
2]/@TripID

What I'm trying to do is come up with the value of 2, 3, 4 or whatever the
next or previous position value may be when clicked.

> Hi Kris,
>
[quoted text clipped - 13 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights
Scott L. Heim [MSFT] - 21 Jun 2005 17:44 GMT
Hi Kris,

Unfortunately I have been unable to find a method to get what you need from
code. I have been able to navigate the records in the table but have been
unsuccessful in determining (via code) where I am in the repeating table.

Sorry I cannot be of more help on this for you.

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights
kfrost - 21 Jun 2005 18:01 GMT
That's ok Scott, I really appreciate the effort.  I think I have another
solution but I just don't know my way around XML in Infopath well enough to
acheive my other alternative either.  Could you by chance check out my newest
post titled
"Retrieving an element attribute from a data source from other view"?

If I can figure that out I think I can accomplish what I need to.  I've got
two projects I need to get finished and I've been stuck on this problem for
two weeks.

Thanks for your help.

kris

> Hi Kris,
>
[quoted text clipped - 8 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights
Greg Collins [InfoPath MVP] - 21 Jun 2005 19:38 GMT
You should be able to do somehting like the following OnClick of the button in a rule or in code:

rowNumber = count(preceding-sibling::my:RepeatingGroup)+1

Signature

Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com

Hello,

I have a page with a repeating table on it that populates with records from
a SQL database on load.  Users click on a record for more detail about it.  
I'm trying to figure out how to get the row position value with VB.Net.  I
know you can use the position () in a rule but I need to store this value in
a global variable for later use and I'm using VB.Net.

If anybody can post a simple example of how to do this I would greatly
appreciate it.

Thanks.

kris
kfrost - 21 Jun 2005 20:21 GMT
Thank you Greg.  I agree something like that would work.  The problem is I'm
doing this in VB.Net and I don't know the syntax for VB.net to make the
statement you posted work.  :)

Thanks.

> You should be able to do somehting like the following OnClick of the button in a rule or in code:
>
[quoted text clipped - 14 lines]
>
> kris
Greg Collins [InfoPath MVP] - 21 Jun 2005 20:43 GMT
Just set a rule on the button to save the XPath value to a secondary dom field... then in your code, just access the field value.

Signature

Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com

Thank you Greg.  I agree something like that would work.  The problem is I'm
doing this in VB.Net and I don't know the syntax for VB.net to make the
statement you posted work.  :)

Thanks.

"Greg Collins [InfoPath MVP]" wrote:

> You should be able to do somehting like the following OnClick of the button in a rule or in code:
>
> rowNumber = count(preceding-sibling::my:RepeatingGroup)+1
Scott L. Heim [MSFT] - 21 Jun 2005 21:42 GMT
Greg,

In order for this to work will the button need to be in a column in the
repeating table? My understanding is Kris wants to just have 4 buttons (not
in the table) that allow record navigation and I don't believe this will
work in this manner.

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights
kfrost - 21 Jun 2005 22:13 GMT
Hello Greg,

This is a form that is bound to a SQL database.  Is there a way to create a
secondary data source for me to write and retrieve info to with a form such
as this?  I did look at the example you referenced me to in another post and
if I weren't using a form bound to SQL I see what you are saying.  But in my
case the Add button to create a data source is grayed out.  Also, if I try to
create a secondary data source, it's just to read info and it has to be a xml
file, web service, database etc.

Is there some other way to create a secondary data source with a database
form that I'm missing?

Thanks.

P.S.  You are correct Scott, these are 4 buttons in a separate view from
where the data source I'm connecting to is first populated.

> Greg,
>
[quoted text clipped - 7 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights
Greg Collins [InfoPath MVP] - 21 Jun 2005 22:39 GMT
You would just need to create a simple .xml file such as the following:

<FormData>
   <SelectedRow></SelectedRow>
</FormData>

and save it as FormData.xml

Then you go to Tools | Data Connections and add the FormData.xml file as a Receive connection.

In your button's rules, set the value of SelectedRow field using the XPath.

In your other view, filter the repeating section based on position() = SelectedRow.

Then setup your other nav buttons to increment/decrement SelectedRow.

Signature

Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com

Hello Greg,

This is a form that is bound to a SQL database.  Is there a way to create a
secondary data source for me to write and retrieve info to with a form such
as this?  I did look at the example you referenced me to in another post and
if I weren't using a form bound to SQL I see what you are saying.  But in my
case the Add button to create a data source is grayed out.  Also, if I try to
create a secondary data source, it's just to read info and it has to be a xml
file, web service, database etc.

Is there some other way to create a secondary data source with a database
form that I'm missing?

Thanks.

P.S.  You are correct Scott, these are 4 buttons in a separate view from
where the data source I'm connecting to is first populated.

"Scott L. Heim [MSFT]" wrote:

> Greg,
>
[quoted text clipped - 7 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights
Scott L. Heim [MSFT] - 21 Jun 2005 22:40 GMT
Hi Kris,

You can actually create a small XML file:

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <nodename></nodename>
</root>

Add this as a "Data Connection" and also choose to add it as a Resource
File. In a sample I have, on the click of a button I access this file and
update the "nodename" node. This information will persist as long as the
InfoPath form is opened. Once you close InfoPath the changes are lost. So
in a scenario where you just need a temporary place to write data, this
works well.

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights
kfrost - 21 Jun 2005 22:57 GMT
Thanks Scott,

I had actually created one but when I went to add it the only option I had
was to retrieve from it so I didn't bother trying to make it work because I
assumed I could only read elements from the file.

But that's good to know for future reference.  I'm pretty close to getting
the code functionality working you helped me with in a separate post.  I've
got another form with similar functionality I need to create after I get this
one to working so I may try Greg's suggestion with your info here to see what
happens.

Thanks

> Hi Kris,
>
[quoted text clipped - 16 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.