相关文章推荐
风度翩翩的伤疤  ·  Python ...·  3 年前    · 
刀枪不入的感冒药  ·  将 Docker Compose ...·  3 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have trouble reading the field. I have tried in different ways but still can not. I want to read the value that the user selected the following 3 values.

Code in XAML

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

Code in C #

List<string> list = new List <string> ();
lista.Add ("Prize");
lista.Add ("Draw");
lista.Add ("Lost");
dgcbc.ItemsSource = list;
                What do you mean by "I want to read the value that the user selected the following 3 values."?  And what is your issue exactly?
– JFTxJ
                Sep 25, 2013 at 11:20
                Don't do it this way. In WPF try to use bindings, it's way easier: wpftutorial.net/DataGrid.html
– Florian Gl
                Sep 25, 2013 at 11:30

This sample might help you in understanding how listbox can be used.

public class Employee
    public string Name { get; set; }
    public string Gender { get; set; }        
<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>

Code-behind

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);
                I'd change the myGrid.ItemsSource = Employees; and Gender.ItemsSource = Genders to bindings instead.
– Bob.
                Sep 25, 2013 at 11:29
                Yes, I understand how it works, and I wrote the rest of the code. Everything works. Thank you and best regards for your help RonakThakkar. :)
– user231605
                Sep 25, 2013 at 21:30
                @RonakThakkar - I am very new to WPF (infact MS technologies) and was looking for this solution for sometime now. This really helped me. I think you should write blog article about it.
– Jadav Bheda
                Jun 14, 2017 at 7:16

I guess you want to enable multi selection in the combobox inside DataGridComboBoxColumn. Following code project does the same.

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

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid …

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.