我有一个附加到gridview数据源的列表,当我在状态字段中从列表中进行更改时,我也希望在gridview中更改状态。
我的循环是通过datagridview,它链接在我的列表中,我认为这个问题是什么?
如何更新DataGridView中的List循环?
MYLIST
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;
}
}
答案 0 :(得分:0)
使用BindingSource
BindingSource bs = new BindingSource();
bs.DataSource = SendMsg;
yourDataGridView.DataSource = bs;