Dropdown to select Pictures - InfoPath Dev
in

InfoPath Dev

Dropdown to select Pictures

Last post 08-05-2010 12:23 PM by Potemkine. 26 replies.
Page 1 of 2 (27 items) 1 2 Next >
Sort Posts: Previous Next
  • 08-05-2010 05:58 AM

    • Toddg
    • Not Ranked
    • Joined on 08-05-2010
    • Posts 14

    Dropdown to select Pictures

    Hello,  I'm new to infopath.  I have created a form and would like to have a dropdown list that displays a small picture beside it when selected.  The picture would change based on the item selected in the dropdown.  Similar to the example below.  Could you provide step by step instructions on how to do this?

  • 08-05-2010 06:08 AM In reply to

    Re: Dropdown to select Pictures

     Hi Toddg, where is all your image? You just have 3 phones model or that can be change ?

  • 08-05-2010 06:14 AM In reply to

    • Toddg
    • Not Ranked
    • Joined on 08-05-2010
    • Posts 14

    Re: Dropdown to select Pictures

    My images are stored in a folder on a network drive.  Is there a better place to store them?  I will most likley have dozens of images.

  • 08-05-2010 06:39 AM In reply to

    Re: Dropdown to select Pictures

    I think it's better if you can put them in a Sharepoint document library, with that you can add a dataconnection and populate your drop down list.

    Another question your are coding in your form with wich language (C#, C# 2003, vb..)?

  • 08-05-2010 06:46 AM In reply to

    • Toddg
    • Not Ranked
    • Joined on 08-05-2010
    • Posts 14

    Re: Dropdown to select Pictures

    This is the first form I ever created.  I'm not familiar with writing code.  We currently don't use sharepoint.

  • 08-05-2010 07:02 AM In reply to

    Re: Dropdown to select Pictures

    Ok, I can propose you a way to do it but you have to code a little

    -In your drop down, in value put the complete path of each images, and in display put your display value

    -You have to use a Rich text field to display the image

    -On Tools, form Option, security and trust, uncheck automatically determine security level and put full trust. Go to programming and select C# in form template code.

    -After that right clic on your drop down, programing, changed event, it will open VSTA.

    -Here some code you have to put in :

     string MyURL = this.MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:test",this.NamespaceManager).Value;
                if(MyURL!="")
                    this.MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:d",this.NamespaceManager).InnerXml="<IMG xmlns=\"http://www.w3.org/1999/xhtml\" SRC=\"" + MyURL + "\" />";

    -you have to change: /my:myFields/my:test by your drop down xpath

    To know it return on infopath and right click on your field on the data source tab, and click copy xpath

    -And change /my:myFields/my:d by your Richtext field.

    Let me know if it's work
           

  • 08-05-2010 07:31 AM In reply to

    • Toddg
    • Not Ranked
    • Joined on 08-05-2010
    • Posts 14

    Re: Dropdown to select Pictures

    OK!  below is the code when I open VSTA.  Where do I past in the new code you supplied?  Sorry!  I'm very new to this.

    Imports Microsoft.Office.InfoPath

    Imports System

    Imports System.Windows.Forms

    Imports System.Xml

    Imports System.Xml.XPath

    Imports mshtml

     

    Namespace ELM_Cost_Request_Form

    Public Class FormCode

    ' Member variables are not supported in browser-enabled forms.

    ' Instead, write and read these values from the FormState

    ' dictionary using code such as the following:

    '

    ' Private Property _memberVariable() As Object

    ' Get

    ' _memberVariable = FormState("_memberVariable")

    ' End Get

    ' Set

    ' FormState("_memberVariable") = value

    ' End Set

    ' End Property

    ' NOTE: The following procedure is required by Microsoft Office InfoPath.

    ' It can be modified using Microsoft Office InfoPath.

    Private Sub InternalStartup(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Startup

    AddHandler DirectCast(EventManager.ControlEvents("CTRL210_5"), ButtonEvent).Clicked, AddressOf CTRL210_5_Clicked

    AddHandler EventManager.XmlEvents("/my:myFields/my:PhonePicker").Changing, AddressOf PhonePicker_Changing

    End Sub

    Public Sub CTRL210_5_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)

    ' Write your code here.

    End Sub

    Public Sub PhonePicker_Changing(ByVal sender As Object, ByVal e As XmlChangingEventArgs)

    ' Ensure that the constraint you are enforcing is compatible

    ' with the default value you set for this XML node.

    ' Write your code here.

    End Sub

    End Class

    End Namespace

  • 08-05-2010 07:39 AM In reply to

    Re: Dropdown to select Pictures

    hum, it seem that you choose VB.... my code is in C#, so

    On Tools, form Option,  Go to programming and click remove code, and then choose C#, and recreate your code project

    -After that right clic on your drop down, programing, changed event, it will open VSTA

    And put the code on this function

  • 08-05-2010 07:43 AM In reply to

    • Toddg
    • Not Ranked
    • Joined on 08-05-2010
    • Posts 14

    Re: Dropdown to select Pictures

     This is the code under changed event.  the last post the code was from changing event.  not sure if it matters.  Thx.

    Imports Microsoft.Office.InfoPath

    Imports System

    Imports System.Windows.Forms

    Imports System.Xml

    Imports System.Xml.XPath

    Imports mshtml

     

    Namespace ELM_Cost_Request_Form

    Public Class FormCode

    ' Member variables are not supported in browser-enabled forms.

    ' Instead, write and read these values from the FormState

    ' dictionary using code such as the following:

    '

    ' Private Property _memberVariable() As Object

    ' Get

    ' _memberVariable = FormState("_memberVariable")

    ' End Get

    ' Set

    ' FormState("_memberVariable") = value

    ' End Set

    ' End Property

    ' NOTE: The following procedure is required by Microsoft Office InfoPath.

    ' It can be modified using Microsoft Office InfoPath.

    Private Sub InternalStartup(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Startup

    AddHandler DirectCast(EventManager.ControlEvents("CTRL210_5"), ButtonEvent).Clicked, AddressOf CTRL210_5_Clicked

    AddHandler EventManager.XmlEvents("/my:myFields/my:PhonePicker").Changing, AddressOf PhonePicker_Changing

    AddHandler EventManager.XmlEvents("/my:myFields/my:PhonePicker").Changed, AddressOf PhonePicker_Changed

    End Sub

    Public Sub CTRL210_5_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)

    ' Write your code here.

    End Sub

    Public Sub PhonePicker_Changing(ByVal sender As Object, ByVal e As XmlChangingEventArgs)

    ' Ensure that the constraint you are enforcing is compatible

    ' with the default value you set for this XML node.

    ' Write your code here.

    End Sub

    Public Sub PhonePicker_Changed(ByVal sender As Object, ByVal e As XmlEventArgs)

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

    End Sub

    End Class

    End Namespace

  • 08-05-2010 07:50 AM In reply to

    • Toddg
    • Not Ranked
    • Joined on 08-05-2010
    • Posts 14

    Re: Dropdown to select Pictures

    Code Language is grayed out???

     

     
  • 08-05-2010 07:52 AM In reply to

    Re: Dropdown to select Pictures

     

    Yes it'normal, you have to click on Remove code to delete your old code files.
  • 08-05-2010 08:18 AM In reply to

    • Toddg
    • Not Ranked
    • Joined on 08-05-2010
    • Posts 14

    Re: Dropdown to select Pictures

    I think I'm in over my head.  Is there a remove code icon or do I just highlight and delete?

  • 08-05-2010 08:26 AM In reply to

    Re: Dropdown to select Pictures

    You have a remove button :

    After you do that just select C#.

  • 08-05-2010 08:49 AM In reply to

    • Toddg
    • Not Ranked
    • Joined on 08-05-2010
    • Posts 14

    Re: Dropdown to select Pictures

     OK!  I'm making progress.  Thanks for being patient with me.  I removed and changed to C#.  I right clicked on the dropdown, selected programming, changed event.  Do I past your code where it says:

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

     

    using Microsoft.Office.InfoPath;

    using System;

    using System.Windows.Forms;

    using System.Xml;

    using System.Xml.XPath;

    using mshtml;

    namespace ELM_Cost_Request_Form_Test_PICS1

    {

    public partial class FormCode

    {

    // Member variables are not supported in browser-enabled forms.

    // Instead, write and read these values from the FormState

    // dictionary using code such as the following:

    //

    // private object _memberVariable

    // {

    // get

    // {

    // return FormState["_memberVariable"];

    // }

    // set

    // {

    // FormState["_memberVariable"] = value;

    // }

    // }

    // NOTE: The following procedure is required by Microsoft Office InfoPath.

    // It can be modified using Microsoft Office InfoPath.

    public void InternalStartup()

    {

    EventManager.XmlEvents[
    "/my:myFields/my:field239"].Changed += new XmlChangedEventHandler(field239_Changed);

    }

    public void field239_Changed(object sender, XmlEventArgs e)

    {

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

    }

    }

    }

     

     

  • 08-05-2010 08:56 AM In reply to

    Re: Dropdown to select Pictures

    Put your code here :

    public void field239_Changed(object sender, XmlEventArgs e)

    {

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

     string MyURL = this.MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:test",this.NamespaceManager).Value;
                if(MyURL!="")
                    this.MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:d",this.NamespaceManager).InnerXml="<IMG xmlns=\"
    http://www.w3.org/1999/xhtml\" SRC=\"" + MyURL + "\" />";

    }

    AND don't forget to change Xpath :)

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