我需要添加其他内容才能将DataTable
与ComboBox
相关联或让它列出项目吗?
目前,它会显示项目,但它们都是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
答案 0 :(得分:3)
将DisplayMemberPath
的{{1}}属性设置为您要显示的ComboBox
中的列名称:
DataTable