[英]add a different ItemsSource for every row in a datagrid combobox
I need to declare a list of TextBox values and a ComboBox with some fields in it. 我需要声明一个TextBox值列表和一个包含某些字段的ComboBox。 Each ComboBox in every row might have 3 or 4 or 5 values,depending on what I pull from a database.
每行中的每个ComboBox可能具有3或4或5个值,具体取决于我从数据库中提取的内容。 But when I declare the fields, all the TextBoxes are binded properly, but the last ComboBox is always empty.
但是,当我声明这些字段时,所有的TextBox都正确绑定,但是最后一个ComboBox始终为空。 I didnt add the TexBoxes and their code for clarity.
为了清楚起见,我没有添加TexBoxes及其代码。 XAML:
XAML:
<DataGrid AutoGenerateColumns="False" x:Name="dataGrid" ItemsSource="{Binding Finalize_routing}" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Height="249" Width="582">
<DataGrid.Columns>
<DataGridComboBoxColumn Header="Stazione" ItemsSource="{Binding Station}" DisplayMemberPath="stazione_id" ></DataGridComboBoxColumn>
</DataGrid.Columns>
main class: 主类:
Finalize_routing = new ObservableCollection<Stazioni_operazioni>();
Finalize_routing.Add(new Stazioni_operazioni
{
Station = new ObservableCollection<Stazioni> { new Stazioni { stazione_id="1"},new Stazioni { stazione_id="2"} }
});
}
InitializeComponent();
DataContext = this;
stazioni_operazioni: stazioni_operazioni:
private ObservableCollection<Stazioni> station;
public ObservableCollection<Stazioni> Station
{
get { return station; }
set
{
if (station != value)
{
station = value;
}
}
}
stazioni: 斯塔齐奥尼:
public class Stazioni{
public string stazione_id { get; set; }
}
there was some problem with the class "stazioni", didnt figure out why.anyway i used a list of strings instead “ stazioni”类存在一些问题,没有弄清楚为什么。反正我使用了一个字符串列表
final_route={"1","2","3"};
Finalize_routing.Add(new Stazioni_operazioni
{
Station = final_route
});
and xaml: 和xaml:
<DataGridTemplateColumn Header="Stazione" Width="80">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding Path=Station,Mode=TwoWay}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.