简体   繁体   English

C#DataGridView更新单元格值

[英]c# DataGridView update cell value

I write code in C# that show value of List in DataGridView: 我用C#编写了在DataGridView中显示List值的代码:

I have this list: 我有这个清单:

List<Order> list = new List<Order> { new Order("Fettina ai Ferri", ""), new Order("1 X", "0.99") };

this list shows in datagridview (ordersDtaGrid): 此列表显示在datagridview(ordersDtaGrid)中:

var source = new BindingSource();
source.DataSource = list;
ordersDtaGrid.DataSource = source;

It works. 有用。

在此处输入图片说明

Now i change a value in list: 现在我更改列表中的值:

list[1].name = "4 X"

And i would like to update datagrid: 而且我想更新datagrid:

var source = new BindingSource();
source.DataSource = list;
ordersDtaGrid.DataSource = source;

And this is result in datagrid: 这就是datagrid的结果:

在此处输入图片说明

There are both the old and the new value. 新旧价值并存。

I have also try adding: 我也尝试添加:

ordersDtaGrid.Refresh();
ordersDtaGrid.Focus();

but nothig. 但不是。

How can i fix this. 我怎样才能解决这个问题。

Thank you. 谢谢。

maybe below can be helpful: 也许下面可能会有所帮助:

list.Clear();
ordersDtaGrid.DataSource = list;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM