【发布时间】:2018-01-04 21:25:00
【问题描述】:
我有一个附加到 gridview 数据源的列表,当我从状态字段中的列表进行更改时,我也想更改 gridview 中的状态。
我的循环是通过datagridview,它链接在我的列表中,我认为问题是这样的吗?
如何在 DataGridView 中更新 List 循环?
我的列表
List<Dados> SendMsg;
填充 Form_Load
SendMsg = GetDados();
gvSent.DataSource = SendMsg;
事件点击
private void btnSend_Click(object sender, EventArgs e)
{
for (int i = gvSent.Rows.Count - 1; i >= 0; i--)
{
if (gvSent.Rows[i].Cells[0].Value != null)
{
//defaultDGV.Rows.RemoveAt(i);
long str = unchecked((long)gvSent.Rows[i].Cells[0].Value);
var query = (from send in SendMsg
where send.MessageSentId == str
select send)
.Update(st => { st.Status = "S"; });
MessageBox.Show(str.ToString());
gvSent.DataSource = query;
}
}
【问题讨论】:
-
什么是
SendMsg?它来自哪里? -
@EmilioCeroleni 我的班级我的列表列表
SendMsg; -
好的。因此,您希望在网格中添加或更改某些值时更新您的列表,对吧?
-
是的,没错,但我认为当它在循环中时它会冻结我的表单,对吗?然后我需要实现线程使用。
-
我将在网络上使用一个服务,如果它成功或失败,相同的服务会返回我,当它成功时我需要为用户显示 STATUS = S