DataGridView.IsCurrentRowDirty
이 true
입니다. false
으로 설정하여 포커스를 잃을 때 RowValidating
을 트리거하지 않습니다.데이터베이스 변경 내용을 적용한 후에 변경 내용을 커밋 한 후에 DataGridView 행이 여전히 더럽습니다.
저는 BindingList<T>
에 연결된 DataGridView
입니다. 나는 CellEndEdit
이벤트를 처리하고 데이터베이스에 변경 사항을 저장합니다. 변경 사항을 저장 한 후 행의 모든 셀이 최신이기 때문에 DataGridView.IsCurrentRowDirty
을 true
으로 설정하고 싶습니다. 그러나 그것은 false
으로 설정됩니다.
행이 포커스를 잃을 때 RowValidating
이 트리거되어 3 개의 셀을 모두 처리하고 유효성을 검사하기 때문에 문제가 발생합니다. 따라서 모든 셀이 유효하고 아무 것도 더티가 아닌 경우에도 여전히 유효성을 검사합니다. 그건 낭비입니다. 여기
void dataGridView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
// Ignore cell if it's not dirty
if (dataGridView.isCurrentCellDirty)
return;
// Validate current cell.
}
void dataGridView_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
{
// Ignore Row if it's not dirty
if (!dataGridView.IsCurrentRowDirty)
return;
// Validate all cells in the current row.
}
void dataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
// Validate all cells in the current row and return if any are invalid.
// If they are valid, save changes to the database
// This is when I would expect dataGridView.IsCurrentRowDirty to be false.
// When this row loses focus it will trigger RowValidating and validate all
// cells in this row, which we already did above.
}
내가 폼의 Validate()
메서드를 호출 할 수 있다고 말했다 게시물을 읽었습니다,하지만 그건 내가 노력하고있어, 이는 화재 RowValidating
의 원인이됩니다 기피.
어떻게 설정할 수 있습니까? DataGridView.IsCurrentRowDirty
을 true
으로 설정 하시겠습니까? 아니면 RowValidating
이 불필요하게 모든 셀의 유효성을 검사하지 못하게하는 방법일까요?
그래, 그게 작동하지 않았다. RowValidating은 행이 포커스를 잃을 때도 계속 발생합니다. 툴팁은'EndEdit()'이 현재 셀에서 작동한다고 말합니다. 비슷한 것이 있다면, EndRowEdit처럼 운이 좋을 수도 있습니다. 그래도 제안을 주셔서 감사합니다! – Ecyrb
누군가가 나를 좋아하는 사람이 있다면. 나는 이것을'datagrid.currentrow.datagrid.endedit()','datagrid.endedit' 그리고 마지막으로'bindingSource.endedit()'호출하여 해결했다. – ppumkin