powershell:combobox只显示System.Data.DataRowView

时间:2017-04-10 12:51:53

标签: wpf powershell combobox

我需要添加其他内容才能将DataTableComboBox相关联或让它列出项目吗?

目前,它会显示项目,但它们都是System.Data.DataRowView,我不知道为什么。

<ComboBox x:Name="WPFDomainUsersBox" HorizontalAlignment="Left" Margin="288,10,0,0" VerticalAlignment="Top" Width="215" Height="23" Text="Domain Users"/>
...
...
...
#create a datatable to bind to our combobox
    $datatable = New-Object system.Data.DataTable
    #Define Columns
    $ColValue = New-Object system.Data.DataColumn "Value",([string])
    $ColText = New-Object system.Data.DataColumn "Text",([string])
    #add columns to datatable
    $datatable.columns.add($ColValue)
    $datatable.columns.add($ColText)

    #List option.
    $DomainUsers = Get-ADUser -Filter *
    ForEach($DUsers in $DomainUsers) {
        #$WPFDomainUsersBox.Items.Add($DUsers.SamAccountName)

        $datarow = $datatable.NewRow()
        #Enter data in the row
        $datarow.Value = $DUsers.SamAccountName
        $datarow.Text = $DUsers.SamAccountName
        #Add the row to the datatable
        $datatable.Rows.Add($datarow)
    }

    $WPFDomainUsersBox.ItemsSource = $datatable.DefaultView

1 个答案:

答案 0 :(得分:3)

DisplayMemberPath的{​​{1}}属性设置为您要显示的ComboBox中的列名称:

DataTable