在Datagrid的不同组合框不同的值 [英] Different values for different comboboxes in Datagrid
问题描述
忍耐一下,因为我是新来的WPF.I有一个包含组合框一个DataGrid
Bear with me, as I'm new to WPF.I have a datagrid which contains comboboxes.
<DataGrid x:Name="dgData" AutoGenerateColumns="False" Margin="131,93,13,101" Grid.Column="1" SelectionChanged="dgData_SelectionChanged">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Subject}" Header="Subject" Width="100"/>
<DataGridComboBoxColumn Header="Subject" x:Name="comboboxColumn1"/>
</DataGrid.Columns>
</DataGrid>
和我使用下面的代码加载取决于不同itemsources在其上点击下拉框由用户:
And I use the following code to load different itemsources depending on which combobox is clicked on by the user:
private void dgData_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (dgData.SelectedIndex == 0)
{
comboboxColumn1.ItemsSource = resolution;
} else if (dgData.SelectedIndex == 1)
{
comboboxColumn1.ItemsSource = codec;
}
}
我如何绑定DGDATA:
How I bind dgData:
List<TicketInfo> ticketsList = new List<TicketInfo>
{
new TicketInfo{ Subject="File", Status="Open"},
new TicketInfo{ Subject="Resolution", Status="Assigned"},
};
dgData.ItemsSource = ticketsList;
public class TicketInfo
{
public string Subject { get; set; }
public string Status { get; set; }
}
现在我还需要一旦用户选择获取组合框的值价值。有没有加载不同的组合框和检索的值不同的项目进行更优雅的方式?
Now I also need to retrieve the value of the combobox once the user chooses the value. Is there a more elegant way to load different items in different comboboxes and retrieving the value?
谢谢!
推荐答案
您不会告诉你如何绑定DGDATA。
You don't show how you bind dgData.
public class TicketInfo
{
public string Subject { get; set; }
public string Status { get; set; }
public List<string> SubjectSubList { get; set; }
}
绑定第二列SubjectSubList
Bind the second column to SubjectSubList
在构建列表ticketsList只是把分辨率在第二首SubjectSubList和编解码器。
When you build List ticketsList just put resolution in the first SubjectSubList and codec in the second.
这篇关于在Datagrid的不同组合框不同的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!