WPF 数据网格组合框
我想在数据网格中显示一个下拉列表,其中包含用户可以选择的不同值。不知何故,我无法显示 ComboBox,而是仅显示该值,就好像它是普通的 TextColumn 一样。下面是我的代码,
<StackPanel Grid.Row="0">
<toolkit:DataGrid Name="definitionGrid" Margin="0,10,0,0" AutoGenerateColumns="False"
CanUserAddRows="False" CanUserDeleteRows="False" IsReadOnly="True"
RowHeight="25" FontWeight="Normal" ItemsSource="{Binding Profile}"
SelectionMode="Single" ScrollViewer.HorizontalScrollBarVisibility="Auto" Width="450"
ScrollViewer.VerticalScrollBarVisibility="Auto" Height="200">
<toolkit:DataGrid.Columns>
<toolkit:DataGridTextColumn Header="Name" Width="80" Binding="{Binding Name}" CellStyle="{StaticResource cellCenterAlign}"/>
<toolkit:DataGridComboBoxColumn Header="Gender" Width="220" SelectedItemBinding="{Binding Gender}" ItemsSource="{Binding Source={StaticResource GenderValues}}" CellStyle="{StaticResource cellCenterAlign}"/>
<toolkit:DataGridCheckBoxColumn Header="Email" Width="60" Binding="{Binding ReceivesEmail}" CellStyle="{StaticResource cellCenterAlign}"/>
<toolkit:DataGridTextColumn Header="Others" Width="80" CellStyle="{StaticResource cellCenterAlign}"/>
</toolkit:DataGrid.Columns>
</toolkit:DataGrid>
</StackPanel>
I want to display a dropdown in the datagrid with different values the user can select from. Somehow I am not able to display a ComboBox, instead it just displays the value as if it were a normal TextColumn. Below is my code,
<StackPanel Grid.Row="0">
<toolkit:DataGrid Name="definitionGrid" Margin="0,10,0,0" AutoGenerateColumns="False"
CanUserAddRows="False" CanUserDeleteRows="False" IsReadOnly="True"
RowHeight="25" FontWeight="Normal" ItemsSource="{Binding Profile}"
SelectionMode="Single" ScrollViewer.HorizontalScrollBarVisibility="Auto" Width="450"
ScrollViewer.VerticalScrollBarVisibility="Auto" Height="200">
<toolkit:DataGrid.Columns>
<toolkit:DataGridTextColumn Header="Name" Width="80" Binding="{Binding Name}" CellStyle="{StaticResource cellCenterAlign}"/>
<toolkit:DataGridComboBoxColumn Header="Gender" Width="220" SelectedItemBinding="{Binding Gender}" ItemsSource="{Binding Source={StaticResource GenderValues}}" CellStyle="{StaticResource cellCenterAlign}"/>
<toolkit:DataGridCheckBoxColumn Header="Email" Width="60" Binding="{Binding ReceivesEmail}" CellStyle="{StaticResource cellCenterAlign}"/>
<toolkit:DataGridTextColumn Header="Others" Width="80" CellStyle="{StaticResource cellCenterAlign}"/>
</toolkit:DataGrid.Columns>
</toolkit:DataGrid>
</StackPanel>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DataGridComboBoxColumn 仅在处于编辑模式时显示 ComboBox;否则它会像普通的 DataGridTextColumn 一样显示。
如果你想显示一个 ComboBox,你可以定义一个 DataGridTemplateColumn:
The DataGridComboBoxColumn only displays ComboBox if it is in edit mode; else it displays like an ordinary DataGridTextColumn.
If you want to display a ComboBox you could define a DataGridTemplateColumn: