0
其複雜因爲即時通過對象UserX做複製列表..我有用戶列表,我想在表中顯示它們。 我需要在角色列默認值的組合框將是用戶的當前角色,我需要通過使用組合框來更改此角色的選項,我不知道如何(可能的角色是:管理員,經理和員工)如何使用DataGrid.Columns與組合框
感謝您的幫助。下面是代碼:
XAML
<DataGrid FontSize="20" Name="dgUsers" ItemsSource="{Binding list}" AutoGenerateColumns="False" ScrollViewer.VerticalScrollBarVisibility="Visible">
<DataGrid.Columns>
<DataGridTextColumn Header="#" Binding="{Binding Id}" />
<DataGridTextColumn Header="Username" Binding="{Binding Username}" />
<DataGridTextColumn Header="Password" Binding="{Binding Password}" />
<DataGridComboBoxColumn Header="Role" ItemsSource="{Binding Role}" />
<DataGridTemplateColumn Header="Remove">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Click="ButtonRemove" Content="Remove User"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
CS
List<User> users = user.getUsersList();
List<Userx> updated = new List<Userx>();
//coping from the list users to list updated. I did it to gete the binding
for (int i = 0; i < users.Count; i++)
updated.Add(new Userx() { Id = i + 1, Username = users.ElementAt(i).getUsername(),
Password = users.ElementAt(i).GetPassword(),
Role = users.ElementAt(i).getRole() });
dgUsers.ItemsSource = updated;
}