这可以填充我的组合框:
$arrUsers = @{}
Get-ADUser -SearchBase 'OU=Users DT,DC=company,DC=co' -Filter * | `
sort -Property SurName, GivenName | %{
if ($_.SurName -AND $_.GivenName){
$arrUsers.Add("$($_.SurName), $($_.GivenName)", $($_.DistinguishedName))
}
}
$arrUsers.GetEnumerator() | sort -Property name | %{
$objUsersDataTableRow = $objUsersDataTable.NewRow()
$objUsersDataTableRow.Text = $_.Key
$objUsersDataTableRow.Value = $_.Value
$objUsersDataTable.Rows.Add($objUsersDataTableRow)
}
$objComboBoxUsers.ValueMember = "Value"
$objComboBoxUsers.DisplayMember = "Text"
$objComboBoxUsers.Datasource = $objUsersDataTable
$objComboBoxUsers.SelectedItem = $objComboBoxUsers.Items[0]
我之后动态添加的此过滤器无法正常工作:
$objComboBoxUsers.Datasource = $objUsersDataTable | where{$_.Text -match $FilterText}
所有组合框项目都替换为 System.Data.DataRow 。
我想更好地理解这一点。
答案 0 :(得分:0)
看起来我对数据源的理解过于简单。
这反过来了:
$objUsersDataTable.defaultview.rowfilter = "Text like '%$($FilterText)%'"
$objComboBoxUsers.Datasource = $objUsersDataTable