Selecting Items From a List Box No Longer Works in Powershell Version 3.0

I've noticed that the script in
this powershell tip of the week no longer seems to fully work in Powershell V3. The selection dialog will pop up as expected, with all of the elments populated, but the selection is not stored in variable '$x'. Any idea what changed and how to get it to
work?
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "Select a Computer"
$objForm.Size = New-Object System.Drawing.Size(300,200)
$objForm.StartPosition = "CenterScreen"
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter")
{$x=$objListBox.SelectedItem;$objForm.Close()}})
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$objForm.Close()}})
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,120)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.Add_Click({$x=$objListBox.SelectedItem;$objForm.Close()})
$objForm.Controls.Add($OKButton)
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(150,120)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({$objForm.Close()})
$objForm.Controls.Add($CancelButton)
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = "Please select a computer:"
$objForm.Controls.Add($objLabel)
$objListBox = New-Object System.Windows.Forms.ListBox
$objListBox.Location = New-Object System.Drawing.Size(10,40)
$objListBox.Size = New-Object System.Drawing.Size(260,20)
$objListBox.Height = 80
[void] $objListBox.Items.Add("atl-dc-001")
[void] $objListBox.Items.Add("atl-dc-002")
[void] $objListBox.Items.Add("atl-dc-003")
[void] $objListBox.Items.Add("atl-dc-004")
[void] $objListBox.Items.Add("atl-dc-005")
[void] $objListBox.Items.Add("atl-dc-006")
[void] $objListBox.Items.Add("atl-dc-007")
$objForm.Controls.Add($objListBox)
$objForm.Topmost = $True
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
$x

Hi,
What is the value of $x?
Make sure that you have copied the whole script, and whether it works on Powershell V2?
Regards,
Yan Li
TechNet Subscriber Support
If you are
TechNet Subscription
user and have any feedback on our support quality, please send your feedback
here.
Cataleya Li
TechNet Community Support

Similar Messages

  • Javascript help to copy selected items from one list to another list on same site

    Hello,
    So I have a request that I am not sure how to handle. I have created a page with a list view webpart that displays all the items from one list.
    The user is then supposed to select off multiple list items and click on a button (most likely a ribbon button) that will take the selected items and copy them to another list on the same SharePoint site.
    I would like to do this with JavaScript, but have only found an example that copies library items to another library.

    Hi KansaiKel,
    According to your description, my understanding is that you want to copy selected list items to another list.
    I suggest you can use JavaScript Client Object Model to achieve it.
    Here is a code snippet for your reference:
    <script type="text/javascript">
    var context = SP.ClientContext.get_current();
    var siteUrl = 'http://sp2013sps/sites/test';
    var clientContext = new SP.ClientContext(siteUrl);
    var web = context.get_web();
    context.load(web);
    var sourceId = SP.ListOperation.Selection.getSelectedList();
    var source = web.get_lists().getById(sourceId);
    var oList = context.get_web().get_lists().getByTitle('Copy');
    context.load(oList);
    var selectedItems = SP.ListOperation.Selection.getSelectedItems(context);
    alert('debut');
    for(var i in selectedItems)
    var currentItem = source.getItemById(selectedItems[i].id);
    context.load(currentItem);
    context.executeQueryAsync(Function.createDelegate(this,test),Function.createDelegate(this,error));
    function test(sender, args){
    var itemCreateInfo = new SP.ListItemCreationInformation();
    var oListItem = oList.addItem(itemCreateInfo);
    oListItem.set_item('Title', currentItem.get_item('Title'));
    oListItem.update();
    oList.update();
    alert('done');
    function error(sender, args){ alert('error');}""
    </script>
    Here is a detailed article for your reference:
    Complete basic operations using JavaScript library code in SharePoint
    Best Regards
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Zhengyu Guo
    TechNet Community Support

  • Select multiple items from a list box as values for a parameter of crystal report and Oracle procedure

    -  I have a  Product list box (asp.net) used as multiple selected values for  a parameter. 
    - The Product ID is defined in the Oracle procedure as NUMBER data type. 
    -  In my crystal report, I have a parameter field allow multiple values as p_product_id type as Number.  This is the code in my Record Selection Formula for the report:
    ({?p_product_id}[1] = -1 OR {Procedure_name.product_id} in {p_product_id})
    -  In C#, this is my code
    List<decimal?> productUnit = new List<decimal?>();
    int counter = 0;
    decimal prod;
    for (int i = 0; i < lstProducts.Items.Count; i++)
                  if (lstProducts.Items[i].Selected)
                                if (decimal.TryParse(lstProduct.Items[i].Value, out prod))
                                    productUnit.Add((decimal?)prod);                              
                                    counter++;
           if (counter == 0)
                       productUnit.Add(-1);                      
    ReportingDAO rDataFactory = new ReportingDAO();
    retVal = rDataFactory.GetProductReport(productUnit);
    public CrystalDecisions.CrystalReports.Engine.ReportDocument GetProductReport(List<decimal?> productUnit)
              CrystalDecisions.CrystalReports.Engine.ReportDocument retVal = new rptProductDownload();
              ReportLogon rptLog = new ReportLogon();
             rptLog.Logon(retVal, "RPT_PRODUCT_DOWNLOAD");
             retVal.SetParameterValue("p_product_id", productUnit); 
    I keep having the "Value does not fall within the expected range" when I debug.  My question is, is the data type I used for procedure/Crystal report/ and C# correct ?  I always have problem with the data type.  Any help would be
    appreciated
    Thank you

    Hi progGirl,
    Thank you for your post, but Microsoft doesn't provide support for CrystalReport now. Please post your question in SAP official site here:
    http://forums.sdn.sap.com/forum.jspa?forumID=313
    Thank you for your understanding.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Removing Items from Populated List-Box

    I have a drop down box populate a list box. (change: ListBox1.addItem(xfa.event.newText)) But I can add more then one of the same selection so how do I remove them from the ListBox. Upon click? somehow? I don't konw the lingo.

    There is a selectedIndex property that will give you back the index of the 1st item that is selected.
    Paul

  • Display selected items in dynamic list box

    I need to display the selected items in a dynamic list box -
    this worked great - but now client wants multiple selected. I do
    have the items comma delimited in single field (but I can change
    that if I need to) - so how do I make those items display as
    selected in list. I'm using asp and standard dreamweaver list based
    on a recordset.

    There is a better approach. I faced a similar problem and put all the logic in a Javascript function. I modified my code to suit your needs.
    My HTML will have the following.
    <body onLoad="javascript:initLanguages();">
      <form name="languageForm">
        <select size="1" name="languagesList">
        </select>
      </form>
    </body>I created a Javascript function
    <script language="Javascript">
      //-- put all your languages here in a Javascript Array if they are fixed.
      //-- If you get the langauges from a Java object (dynamic or configurable), generate the Javascript in that object and insert a scriptlet in the HTML that plugs in the generated Javascript into this HTML. If so, take care of the quotes and double quotes. They are tricky !!!
      var languageArray = new Array("Fran?ais", "English", "Espanol", "Deutsch", "Italiano");
      function initLanguages ()
        var listCounter = 0;
        for (var ind=0; languageArray != null && ind < languageArray.length; ++ind)
          var obj = eval("new Option" + languageArray[ind]);
          eval("document.languagesForm.languagesList.options[listCounter]=" + "new Option" + languageArray[ind]);
          if(document.languagesForm.languagesList.options[listCounter].value == "<%= selectedLanguage %>")
            document.languagesForm.languagesList.options[listCounter].selected = true;
          listCounter += 1;
    </script>
    selectedLanguage is something you get in the Java code
    <%
      selectedLanguage = myObj.getSelectedLanguage();
    %>

  • Select items from a list

    Hi,
    in a backing bean (MyBean) which exposes a List of MyItem objects.
    I show this list in a report page using a dataTable.
    I associate a link "details" to each row and I want that selecting this link a detail page is shown, with all the data for the specific item selected.
    How can I do this ?
    Pietro

    ok! I've wrapped my item List in a ListDataModel obejct with very few changes to my code and set up detail method as:
    /** list bounded to the report page */
    private ListDataModel myList;
    /** detailed item */
    private MyItem myItem;
    /** action called from a single report page row */
    public String itemDetails(){
    this.myItem = (MyItem) myList.getRowData();
    // goes to the item details page
    return "details";
    and it works well.
    thanks!
    Pietro

  • How to remove an item from a list box?

    Here's my previous code.
    I hope someone can help me. Thanks.
    public partial class frmJaialai : Form
    List<Jaialai> source;
    public frmJaialai()
    InitializeComponent();
    private void frmJaialai_Load(object sender, EventArgs e)
    source = new List<Jaialai>();
    private void btnAdd_Click(object sender, EventArgs e)
    if (IsValidData())
    int bet;
    if (string.IsNullOrEmpty(txtJaialaiNumber.Text) || !Int32.TryParse(txtBet.Text, out bet))
    MessageBox.Show("Must be a required field.", "Entry Error");
    return;
    var existingProduct = source.Where(x => x.JaialaiNumber == txtJaialaiNumber.Text).SingleOrDefault();
    if (existingProduct != null)
    existingProduct.Bet += bet;
    else
    source.Add(new Jaialai { Bet = bet, JaialaiNumber = txtJaialaiNumber.Text });
    lstJaialaiNumbersList.DataSource = null;
    lstJaialaiNumbersList.DataSource = source;
    txtJaialaiNumber.Text = "";
    // save the jai-alai numbers list on a txt file
    const string sPath = @"C:\Automated Jai-alai Program\Jai-alai Numbers List.txt";
    System.IO.StreamWriter SaveFile = new System.IO.StreamWriter(sPath);
    foreach (var item in lstJaialaiNumbersList.Items)
    SaveFile.WriteLine(item);
    SaveFile.Close();
    public class Jaialai
    public string JaialaiNumber { get; set; }
    public int Bet { get; set; }
    public override string ToString()
    return string.Format("{0} = {1}",
    JaialaiNumber, "₱" + Bet.ToString());
    private bool IsValidData()
    return Validator.IsPresent(txtJaialaiNumber) &&
    Validator.IsPresent(txtBet) &&
    Validator.IsInt32(txtBet);

    Hi ,
    Here is a sample about remove Item from listBox.
    // listBox1.Items.Clear();// remove all
    int SelItemCount = listBox1.SelectedItems.Count;
    for (int i = 0; i < SelItemCount; i++)
    listBox1.Items.Remove(listBox1.SelectedItem);//remove which one you selected
    You also can check in MSDN
    https://msdn.microsoft.com/en-us/library/aa983551(v=vs.71).aspx
    Best regards,
    Kristin
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Javascript needed - need checkbox to check automatically based on selected item from dropdown list

    I am building a fillable form.  In this form, I have created items in a dropdown list.  Based on the item picked from the dropdown list, I need a corresponding checkbox to be checked.  I am certain there is an easy javascript to resolve my current problem.  Please assist.
    For example: dropdown list field (SubSupplier1) -   Demolition                            export value 2
                                                                                    Rough Carpentry Labor       export value 4
                                                                                    Rough Carpentry Material    export value 3
    I need the corresponding checkbox (SalesTax1) to automatically be checked when Demolition (export value 2) or Rough Carpentry Material (export value 3) is selected.
    Thank you,
    Jennifer

    Hi Jennifer,
    This should help you do what you need. Place it in the Custom Calculation property of the dropbox and select "commit selected value immediately" in the fields options:
    var drop = this.getField("SubSupplier1");
    var check = this.getField("SalesTax1");
    if ((drop.value == 2) || (drop.value == 3)){
    check.checkThisBox(0,true);
    else {
    check.checkThisBox(0,false);
    The code is asking if the export value of the field is either '2' or '3' and if so, check the box.
    Otherwise uncheck the box.
    If you don't want it to uncheck on other selections, remove the 'else' section of code.

  • Second list of items from selected item in first list

    Hi all,
    I have 2 dropdown lists in my jsp page. i am retrieving data from database for my first list box. the second list box data should be displayed when user select an item from the first list. the selected item from first list is necessary to get another list of items in second list. i dont want to use any buttons or submits. i want to redirect the data to the same page to get another list when user click one option from first list. Thanks in advance for any suggestion.

    use ajax or store the data in javascript array

  • Getting multiple values from a list box

    Hi,
    I am not able to get multiple selected values from a list box using the getParameterValues(). I used the following code..
    String[] names=request.getParameterValues("lname");
    can anyone tell me what the error is or is there any other way i can get multiple selected values from a list box.
    Thanks
    Satish

    Fragment 1
    This is the JSP Code am using for testing
    <%
    String[] name =request.getParameterValues("D1");
    if(name.length==1)
    String value=name[0];
    Instead of name.lenght==1 try with name!=null
    Fragment 2
    out.println(value);
    replace the above fragment with
    %>
       <%-- print result -->
       <%=name[0]%>
    <%
    Fragment 3
    else
    %>
    The list box D1 is a multiple select list box.
    If it still doesn't work, check that the checkboxes have the same name as well as different values
    <input type="checkbox" name="D1" value="1">
    <input type="checkbox" name="D1" value="2">I hope this helps :-)
    Good luck
    touco
    ps: i want duke

  • After selecting the value from the list box, want to disable checkbox

    hi guru,
    After selecting the value from the list box, want to disable checkbox and custom control textbox(container) in module pool.
    so please help me on this.
    thanx,
    man

    in PBO,
    loop at screen.
      if screen-name = your textbox's name.
        screen-input = 0.
        modify screen.
      endif.
    endloop.

  • How to get the selected items from listbox

    Regarding listbox i have two questions
    1) I want to get the selected items as per the order in which ihave selected.Presently i'm getting in the ascending order.For example after selcting the 1,2,6 if i select 3 then its giving 1,2,3,6.But i want it in the order 1,2,6,3
    2)I want to select items from a single list box to many other listboxes.(ie) my first selection should goto first,second one to the second listbox and like this.How should i write the logic.
    please give me a suggestion.

    In order to have the selected items line up in accordance to the selection order, please do it one at a time. (That's the limit for that VI)
    If you need more than that (i.e. to regconize which item clicked first and which one comes later), you may have to figure it out ya
    Wish you good luck. Perhaps, someone else has a already made vi.
    Cheers!
    ian.f
    Ian F
    Since LabVIEW 5.1... 7.1.1... 2009, 2010
    依恩与LabVIEW
    LVVILIB.blogspot.com

  • Getting selected item from combobox itemrenderer and storing in object

    Hi Guys,
    Can anyone help me in this regard. Its very urgent.
    I have a combo box itemrenderer in datagrid column. I want to get the user selected item from the dropdown of the row(s) (User may select values from combo box from multiple rows of datagrid) and corressponding values of all other columns of the rows and store it in an object . Then pass this object to database to update only those rows that user has changed.
    I am able to get the selected item from combo box using "event.currentTarget.selectedItem" and corressponding values of all other columns of the rows using "valueSelect.ID", etc where valueSelect is object which contains data for datagrid. But am stuck up with, how to store the selected item value of the combobox  and corressponding values of all other columns of the rows into an Object ?.
    Can anybody help me with sample to store selected item from combobox and its corressponding values of all other columns into an object which i can send to db...?
    Kindly help me in this regard.
    Thanks,
    Anand.

    Hi!
    Are you using a collection of VO or DTO as the dataprovider of the combobox component?
    If so, have you created some attribute there to control the user's selection in the combobox?
    For instance:
    private var selected:Boolean = false;
    If your solution fits this approach, you may create a new collection that contains just the objects that were selected by the user, it means you can loop through the datagrid's dataprovider and only insert in this new collection those objects that have the attribute "selected" set to true.
    For instance:
    private function getSelectedRecords(datagridDataProvider:ArrayCollection):ArrayCollection
        var newCollection:ArrayCollection = new ArrayCollection();
        for each (var item:Object in datagridDataProvider)
            if (item.selected)
                newCollection.addItem(item)
        return newCollection;
    Afterwards, you may serialize this new collection with your back-end.
    Hope it helps you!
    Cheers,
    @Pablo_Souza

  • How to move items from one list to other

    hi all,
    in jsp page i have twolist boxes. i want to move item from one list to other list on click of add or move button. can u plz suggest me an answer for the above. thank u
    Regards sangeet

    This link should help. Remove from one list and add to the other using Javascript.
    http://www.mredkj.com/tutorials/tutorial006.html

  • Get Selected Items from ListBox

    Hi,
    How do I get the Selected items of a List in Flex.
    I am using a multi-select List.
    Thx

    Never mind..I got it.
    it as simple as that:
    Alert.show (lst.selectedItem.fieldname);
    ;)

Maybe you are looking for