gpt4 book ai didi

wpf - 两种方式 wpf datagrid 绑定(bind)到数据库

转载 作者:行者123 更新时间:2023-12-04 20:55:21 25 4
gpt4 key购买 nike

大家好,

我想以两种方式绑定(bind) WPF 数据网格。我曾尝试遵循 XAML:

<Grid>
<my:DataGrid x:Name="dataGrid" AutoGenerateColumns="False" Margin="8">
<my:DataGrid.Columns>
<my:DataGridTextColumn Header="Header" Binding="{Binding pCode}" IsReadOnly="True" />
<my:DataGridTextColumn Header="Header" Binding="{Binding pName}" IsReadOnly="True" />
<my:DataGridTextColumn Header="Header" Binding="{Binding pStock}" IsReadOnly="True" />
<my:DataGridTextColumn Header="Header" Binding="{Binding pGroup}" IsReadOnly="True" />
<my:DataGridTextColumn Header="Header" Binding="{Binding pPrice, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</my:DataGrid.Columns>
</my:DataGrid>
</Grid>

更新
ProductsTableAdapters.TempTA tempTA = new WpfDataGridBinding.ProductsTableAdapters.TempTA();
Products.TempDataTable tempDT = new Products.TempDataTable();

public Window1()
{
InitializeComponent();

tempDT = tempTA.GetData();
dataGrid.ItemsSource = tempDT;

}

这就是我绑定(bind)到数据网格的方式。现在,每当我更改 DataGrid 中的价格时,我都想更新数据库。我更想问的是,我只会更新值已更改的行,而不是所有行。

谢谢
请编码(帮助)我....

最佳答案

您不需要显式设置双向绑定(bind)。这是默认设置。因为您绑定(bind)到 TableAdapter,所以每当您在网格中进行更改时,这些更改都会反射(reflect)在 TableAdapter 中。您现在需要做的就是将这些更改写入数据库。在 TableAdapter 的 RowChanged 事件中,只需调用 TableAdapter.Update 将更改写入数据库。

关于wpf - 两种方式 wpf datagrid 绑定(bind)到数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3084831/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com