powershell根据另一个组合框上的选定项目填充组合框 [英] powershell populate combobox basing on the selected item on another combobox

查看:67
本文介绍了powershell根据另一个组合框上的选定项目填充组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这次我遇到了另一个 PowerShell GUI 挑战.我有一个包含两个不同组合框(组合框 1 和组合框 2)的表单

This time I am stuck with another PowerShell GUI challenge. I have a Form that contains two different comboboxes (combobox1 and combobox2)

我想做的是:第一个组合框显示我拥有的所有客户端的列表,第二个组合框显示可供第一个组合框选择的客户端使用的所有不同邮箱.

What I want to do is: The first combobox to show a list of all the clients that I have and the second combobox to show all the different mailboxes that are available for the client that has been selected on the first combobox.

我再一次不知道该怎么做,所以我向你们寻求建议.

Once again I don't know how to do it so I am asking you guys for advise.

我设法在第一个组合框上显示了所有客户的列表.但我从来没有设法填充第二个组合框,显示该特定客户端可用的不同邮箱.

I managed to show a list of all the clients on the first combobox. But I have never managed to populate the second combobox showing the different mailboxes available for that specific client.

这是我到目前为止的代码,问题是我不知道如何触发第二个组合框的填充"

This is the code I've got so far, the issue is that I don't know how to do to "trigger the population of the second combobox"

$MainForm_Load={
#TODO: Initialize Form Controls here
add-pssnapin Microsoft.Exchange.Management.PowerShell.E2010 -ea silentlycontinue
import-module activedirectory

$Clients = Get-ADOrganizationalUnit -SearchBase 'OU=Clients,DC=asp,DC=xaracloud,DC=net' -SearchScope Onelevel -Filter * -Properties Description

foreach ($client in $Clients)
{
    $CurrentClient = "{0} ({1})" -f $client.Name, $client.Description
    Load-ComboBox $combobox1 $CurrentClient -Append
}

if ($combobox1.SelectedIndex -gt -1)
{

    $ClientSelected = ($combobox1.SelectedItem) -replace " \(.*\)"

    $Mailboxes = Get-Mailbox -OrganizationalUnit $ClientSelected
    foreach ($mailbox in $Mailboxes)
    {
        $CurrentMailbox = "{0} ({1})" -f $mailbox.Name, $mailbox.Alias
        Load-ComboBox $combobox2 $CurrentMailbox -Append
    }

}

}

请注意,为了根据第一个组合框的选择填充第二个组合框,我必须查询我的交换服务器,这需要几秒钟.有没有办法显示一个进程栏来表示正在处理请求?我不希望用户认为脚本什么都不做或不起作用.

Please note that in order to populate the second combobox basing on the selection of the first one I have to query my exchange server and that takes a few seconds. Is there any way of showing a process bar to say that the request is being processed? I don't want the user to think that the script is doing nothing or that it doesn't work.

推荐答案

删除|来自 Get-Mailbox 行的 Out-String 并添加使用以下选项之一(当然还有更多):

Remove the | Out-String from the Get-Mailbox line and add use one of this options(of course there's more):

使用 ComboBox.SelectionChangeCommitted 事件:

当用户更改所选项目并且该更改显示在 ComboBox 中时发生"

"Occurs when the user changes the selected item and that change is displayed in the ComboBox"

$combobox2_SelectionChangeCommitted={

  $Mailboxes = Get-Mailbox -OrganizationalUnit $ClientSelected
  foreach ($mailbox in $Mailboxes)
  {
      $CurrentMailbox = "{0} ({1})" -f $mailbox.Name, $mailbox.Alias
      Load-ComboBox $combobox2 $CurrentMailbox -Append
  }

}

使用按钮:

$button1_Click={

$Mailboxes = Get-Mailbox -OrganizationalUnit $ClientSelected
  foreach ($mailbox in $Mailboxes)
  {
      $CurrentMailbox = "{0} ({1})" -f $mailbox.Name, $mailbox.Alias
      Load-ComboBox $combobox2 $CurrentMailbox -Append
  }
}

此外,还有更多选择,您可以从上述之一开始...

Also, there's more options, you can start with one of the above...

这篇关于powershell根据另一个组合框上的选定项目填充组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆