DisplayMemberPath
可以与别名列名一起使用。
填充ComboBox
的代码:
SQLiteConnection conn = MainWindow.DatabaseConnection();
try
{
conn.Open();
}
catch (Exception ex)
{
System.Windows.MessageBox.Show(ex.ToString());
}
string sql = @"SELECT CameraID,
Vendor.VendorName || ' ' || Camera.Model AS CameraName,
Camera.Active
FROM Camera
JOIN Vendor USING (VendorID)
ORDER BY CameraName";
SQLiteCommand com = new SQLiteCommand(sql, conn);
DataTable dataTable = new DataTable("Camera");
SQLiteDataAdapter ad = new SQLiteDataAdapter(sql, conn);
ad.Fill(dataTable);
_dataSet.Tables.Add(dataTable);
comboBoxTableEditMount.ItemsSource = dataTable.DefaultView;
XAML:
<ComboBox x:Name="comboBoxTableEditMount"
Grid.Column="2"
Grid.Row="8"
DisplayMemberPath="CameraName"
SelectedValue="{Binding CameraID}"
SelectedValuePath="MountID"
Style="{DynamicResource ComboboxData}"
Width="135"
Margin="-80,0,0,0" />
ComboBox
未列出任何商品。如果我将DisplayMemberPath
更改为CameraID
,则会显示数字。