Problem setting DataSource of a DataGridView

前端 未结 2 1241
暗喜
暗喜 2021-01-15 13:59

What happens here is when in the form opens, it shows the contextMenu and display the DataGridView on it with the value of dataSet1. But when I click the button to change th

2条回答
  •  失恋的感觉
    2021-01-15 14:26

    Just changing the datasource of a control does not tell it to re-bind(refresh) its data from that new datasource. You need to execute the control's DataBind() command after you change its datasource.

    So after this:

    dataGridView1.DataSource = ds;
    

    try adding this:

    dataGridView1.DataBind();
    

提交回复
热议问题