DataGridView 셀의 값을 프로그래밍 방식으로 변경 한 후에는 원본을 업데이트 할 수 없습니다. 내가 무엇을 할 수 있을지?DataGridViews 소스를 프로그래밍 방식으로 업데이트 하시겠습니까?
datagridview1.DataSource = bindingsource1;
datagridview1.Rows[0].Cells[0].Value = "1";
DataGridView 셀의 값을 프로그래밍 방식으로 변경 한 후에는 원본을 업데이트 할 수 없습니다. 내가 무엇을 할 수 있을지?DataGridViews 소스를 프로그래밍 방식으로 업데이트 하시겠습니까?
datagridview1.DataSource = bindingsource1;
datagridview1.Rows[0].Cells[0].Value = "1";
당신은 당신이 수동으로이 작업을 수행 할 필요가 있다고 생각 다음지며 EndEdit에게
datagridview1.EndEdit();
datagridview1.Refresh();
를 사용해야 편집 모드에있는 경우 DataGridView에
datagridview1.Refresh();
에 새로 고침을 호출해야합니다. 데이터를 Gridview에 바인딩하십시오. gridview를 업데이트하십시오. 업데이트 된 셀을 선택하고 데이터를 다시 데이터에 저장 한 다음 데이터 소스에서 데이터를 가져 와서 gridview를 새로 고칩니다.
당신은 내가, 바인딩 소스에 대한지며 EndEdit()를 호출하여 해결할 수 동일한 문제가 있었다있다 내 코드
private void button2_Click(object sender, EventArgs e)
{
this.Validate();
try
{
dgvArticles.CurrentRow.Cells[1].Value = txtSubject.Text;
dgvArticles.CurrentRow.Cells[2].Value = rtbBodyContent.Text;
dgvArticles.CurrentRow.Cells[3].Value = pbPrimaryPicture.Image;
dgvArticles.CurrentRow.Cells[4].Value = pbSecondaryPicture.Image;
dgvArticles.CurrentRow.Cells[5].Value = pbThirdPicture.Image;
}
catch
{
MessageBox.Show(e.ToString());
}
AccessingNetFamerDatabase anfdArticles = new AccessingNetFamerDatabase();
if (_dsArticles!= null)
{
SqlCommandBuilder _sqlCBArticles = new SqlCommandBuilder(AccessingNetFamerDatabase._sqlDataAdapter);
AccessingNetFamerDatabase._sqlDataAdapter.Update(_dsArticles.Tables[0]);
}
}
아래 여기의 DataSet
를 다시 작성해야합니다.
예를 들면
bs.EndEdit();
int x1 = data.Update(dt);
업데이트는 업데이트 된 행의 수를 반환했습니다. EndEdit을 추가하기 전에는 항상 0입니다.