11

我无法阅读该领域。我尝试过不同的方式,但仍然不能。我想读取用户选择以下 3 个值的值。

XAML 中的代码

<DataGridComboBoxColumn X:Name="dgcbc" Header="Wynik"/>

C#中的代码

List<string> list = new List <string> ();
lista.Add ("Prize");
lista.Add ("Draw");
lista.Add ("Lost");
dgcbc.ItemsSource = list;
4

2 回答 2

22

此示例可能会帮助您了解如何使用列表框。

public class Employee
{
    public string Name { get; set; }
    public string Gender { get; set; }        
}

XAML

<StackPanel>
  <DataGrid AutoGenerateColumns="False" Name="myGrid" Margin="10">
     <DataGrid.Columns>
        <DataGridTextColumn Binding="{Binding Path=Name}" />             
        <DataGridComboBoxColumn Width="100" x:Name="Gender" 
                    SelectedValueBinding="{Binding Gender, Mode=TwoWay}"  
                    DisplayMemberPath="{Binding Gender}" />
     </DataGrid.Columns>
  </DataGrid>
  <Button Name="ShowPersonDetails"  
          Content="Show Person Details" 
          Width="200" Height="30"  
          Click="ShowPersonDetails_Click" Margin="10" />
</StackPanel>

代码隐藏

public partial class WPFDataGridComboBox : Window
{
    public List<Employee> Employees { get; set; }
    public List<string> Genders { get; set; }

    public WPFDataGridComboBox()
    {
        Employees = new List<Employee>()
        {
            new Employee() { Name = "ABC", Gender = "Female" },
            new Employee() { Name = "XYZ" }
        };

        Genders = new List<string>();
        Genders.Add("Male");
        Genders.Add("Female");

        InitializeComponent();
        myGrid.ItemsSource = Employees;
        Gender.ItemsSource = Genders;
    }

    private void ShowPersonDetails_Click(object sender, RoutedEventArgs e)
    {
        foreach (Employee employee in Employees)
        {
            string text = string.Empty;
            text = "Name : " + employee.Name + Environment.NewLine;
            text += "Gender : " + employee.Gender + Environment.NewLine;
            MessageBox.Show(text);
        }
    }
}
于 2013-09-25T11:26:13.723 回答
0

我猜您想在 DataGridComboBoxColumn 内的组合框中启用多选。以下代码项目也是如此。

http://www.codeproject.com/Articles/21085/CheckBox-ComboBox-Extending-the-ComboBox-Class-and

于 2013-09-25T12:36:46.307 回答