본문 바로가기
Winform

Devexpress Grid LostFocus Event

by 캡틴노랑이 2018. 12. 19.
반응형

그리드 내의 컬럼마다 계산식 등등이 있을때, 해당 식 적용 방법. 

경우의 수

1.row 변경

2.동일 row 내에서 focuscolumn 변경

3.외부 컨트롤로 focus이동 

//값 변경시 
advBandedGridView.KeyDown += AdvBandedGridView_KeyDown;
//row의 focus column이 변경되었을 시
advBandedGridView.FocusedColumnChanged += AdvBandedGridView_FocusedColumnChanged;
//grid내에서 row변경시 
advBandedGridView.BeforeLeaveRow += AdvBandedGridView_BeforeLeaveRow;            
//grid의 focus를 잃었을 때 
advBandedGridView.LostFocus += AdvBandedGridView_LostFocus;


private void AdvBandedGridView_KeyDown(object sender, KeyEventArgs e)
{
    if (advBandedGridView.GetFocusedDataRow() != null)
        qtyCalc(advBandedGridView.GetFocusedDataRow());
}

private void AdvBandedGridView_FocusedColumnChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedColumnChangedEventArgs e)
{
    if (advBandedGridView.GetFocusedDataRow() != null)
        qtyCalc(advBandedGridViewStoreList.GetFocusedDataRow());
}        

private void AdvBandedGrid_BeforeLeaveRow(object sender, DevExpress.XtraGrid.Views.Base.RowAllowEventArgs e)
{
    if (advBandedGridView.GetFocusedDataRow() != null)
        qtyCalc(advBandedGridViewStoreList.GetFocusedDataRow());
}

private void AdvBandedGridView_LostFocus(object sender, EventArgs e)
{
    float UNIT_CNT = 0;
    float QN_UNIT = 0;
    float QN_EA = 0;
    float QN = 0;

    DataRow dr = advBandedGridViewStoreList.GetFocusedDataRow();
    DevExpress.XtraGrid.Views.Base.ColumnView view = (DevExpress.XtraGrid.Views.Base.ColumnView)sender;

    if (advBandedGridViewList.GetFocusedDataRow() == null || dr == null)
        return;

    DevExpress.XtraEditors.TextEdit editor = (DevExpress.XtraEditors.TextEdit)view.ActiveEditor;

    if (view.FocusedColumn.FieldName.Equals("QN_UNIT"))//column search
    {
        if (!float.TryParse(editor.EditValue.ToString(), out QN_UNIT))
            QN_UNIT = 0;

        if (!float.TryParse(dr["QN_EA"].ToString(), out QN_EA))
            QN_EA = 0;
    }
    else
    {
        if (!float.TryParse(dr["QN_UNIT"].ToString(), out QN_UNIT))
            QN_UNIT = 0;

        if (!float.TryParse(editor.EditValue.ToString(), out QN_EA))
            QN_EA = 0;
    }

    if (!float.TryParse(advBandedGridViewList.GetFocusedDataRow()["UNIT_CNT"].ToString(), out UNIT_CNT))
        UNIT_CNT = 0;

    QN = (UNIT_CNT * QN_UNIT) + QN_EA;
    dr["QN"] = QN.ToString();
}


반응형

댓글