공부/Devexpress
[Devexpress Winform] GridView 에서 ValidatingEditor 이벤트때 변경 전 데이터 가져오기
복제고양이
2025. 1. 5. 20:43
300x250
GridView의 ValidatingEditor 이벤트에 있는 BaseContainerValidateEditorEventArgs에서는 변경된 후의 데이터만 가져올 수 있다.
이럴때는 GridView 인스턴스에서 ActiveEditor의 OldEditValue를 가져온다.
예를 들어, GridView gridView 가 있을 때,
ValidatingEditor 이벤트 발생시
변한 값이 변경 전 값과 같을 때 다른 작업을 하거나 넘길 수 있다.
gridView.ValidatingEditor += (s, e) =>
{
string name = e.Value as string;
if (gridView_Lamp.FocusedColumn.FieldName == "Validate할 column 필드이름")
{
BaseEdit edit = gridView_Lamp.ActiveEditor;
var oldVal = edit.OldEditValue?.ToString()?? "";
if (e.Value.ToString().Equals(oldVal))
{
//다른 작업을 하거나 그대로 리턴
}
else if (oldVal.IsNullOrEmpty())
return;
else if (valid error 조건)
{
e.Valid = false;
e.ErrorText = "에러 메세지 텍스트";
}
}
};
참고
Add the e.OldValue property to the BaseContainerValidateEditorEventArgs class | DevExpress Support
Add the e.OldValue property to the BaseContainerValidateEditorEventArgs class
You have yet to view any tickets. Your search criteria do not match any tickets. A server error occurred while processing your request. Please try again at a later time.
supportcenter.devexpress.com
+ 추가 )
OldEditValue가 null인 경우 예외가 발생할 수 있다.
널체크를 하도록 수정했다.
이후 oldVal이 null이면 체크할 필요가 없어서 넘어가게 만들었다.
반응형