我正试图找出方法。
背景: 基本上,我是通过DataGrid将Google Spreadsheet的内容移植到WPF应用程序的。 Spreadsheet每列都有一个下拉菜单,用于查找另一张表上的值,因此用户只能为该列中的该单元格选择有效数据,而不用输入任何内容。 我已经在字典中加载了这些LookupValues,以及在使用TextColumns时在DataGrid单元格中具有工作表数据。 最后一步是使用ComboBoxColumns而不是TextColumns,但是我还不知道如何加载和绑定它们并显示正确的值,因此在WPF应用程序中,当打开ComboBox下拉列表时,它将显示可选值,并且仅允许这些值
我有一个表示列的枚举
public enum ColumnEnumeration
{
Time = 0,
ReplacedUser = 1,
ReplacementUser = 2,
Class = 3,
Location = 4,
AdditionalInfo = 5
}
字典,其中每个枚举值都包含字符串列表
private Dictionary<Replacement.ColumnEnumeration, List<String>> LookupValues;
我想绑定到我的DataGrid组合框
<DataGrid Name="ExcelDataView" Grid.Row="1"
BorderThickness="1 0 1 1" BorderBrush="Black"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
AutoGenerateColumns="False"
ColumnWidth="*"
RowBackground="WhiteSmoke"
Background="LightBlue"
CanUserAddRows="False"
BeginningEdit="ExcelDataView_BeginningEdit"
CellEditEnding="ExcelDataView_CellEditEnding"
RowEditEnding="ExcelDataView_RowEditEnding">
<DataGrid.Columns>
<DataGridComboBoxColumn Header="Time" ItemsSource="{Binding TimeText, Mode=TwoWay}" Width="70" CanUserSort="False" />
<DataGridComboBoxColumn Header="Replaced User" ItemsSource="{Binding ReplacedUser, Mode=TwoWay}" Width="140" CanUserSort="False" />
<DataGridComboBoxColumn Header="Replacement User" ItemsSource="{Binding ReplacementUser, Mode=TwoWay}" Width="140" CanUserSort="False" />
<DataGridComboBoxColumn Header="Class" ItemsSource="{Binding Class, Mode=TwoWay}" Width="170" CanUserSort="False" />
<DataGridComboBoxColumn Header="Location" ItemsSource="{Binding Location, Mode=TwoWay}" Width="170" CanUserSort="False" />
<DataGridComboBoxColumn Header="Info" ItemsSource="{Binding AdditionalInfo, Mode=TwoWay}" CanUserSort="False" />
<DataGridCheckBoxColumn Header="Mark" Binding="{Binding Marked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" CanUserSort="False" Width="50">
<DataGridCheckBoxColumn.CellStyle>
<Style>
<EventSetter Event="CheckBox.Checked" Handler="OnExcelDeleteColumnChecked"/>
<EventSetter Event="CheckBox.Unchecked" Handler="OnExcelDeleteColumnUnchecked"/>
</Style>
</DataGridCheckBoxColumn.CellStyle>
</DataGridCheckBoxColumn>
</DataGrid.Columns>
</DataGrid>
以及已经加载了其内容的DataGrid
ExcelDataView.ItemsSource = Replacement.LoadFromExcel(GoogleCore.SheetService, fileId, ActiveDate.ToString(Settings.SpreadsheetSheetNameFormat), Settings.SpreadsheetDataRange);
我可以找到但还没有找到的示例。