簡體   English   中英

RepositoryItemLookupEdit 新值在處理前消失

[英]RepositoryItemLookupEdit new value disappears before being processed

我在網格中有一個 LookupEdit 需要能夠接受新值。 當我輸入新值並按“Enter”或“Tab”時,它會通過 ProcessNewValue 事件正常保存,但是當我輸入一個值並單擊網格中的其他地方、另一個單元格或僅在空白處時,該值完全消失. 通過實現其他幾個事件並設置斷點,我發現該值在“CloseUp”事件觸發之前消失了。 Validating、EditValueChanged、EditValueChanging、ProcessNewValue、Closed、Leave 甚至 GetNotInListValue 都不會因為空值而被調用。

誰能想到一些我還沒有找到的設置,或者這個值會消失的任何其他原因......以及我如何阻止它發生?

找到了有效的解決方法

我依次實現了以下 3 個事件來解決這個問題。 我仍然不知道是什么導致了它,或者如何去預防它。 這是一種解決方法,而不是解決方案,應如此對待。 我最終不得不手動調用ProcessNewValue方法,並強制該值等於文本字段,稍后將文本字段返回到該值。 不是最順暢的操作,但它確實有效。

private void repPatchNum1_EditValueChanging(object sender, DevExpress.XtraEditors.Controls.ChangingEventArgs e)
    {
        string surfaceSoftware = vwSurfaceSoftware.GetRowCellDisplayText(vwSurfaceSoftware.FocusedRowHandle, "SurfaceSoftware");
        if (string.Compare(surfaceSoftware, SOFTWARE_CHECK, true) == 0)
        {
            string version = vwSurfaceSoftware.GetRowCellDisplayText(vwSurfaceSoftware.FocusedRowHandle, "Version");
            if (version.ToLower().Contains(VERSION_CHECK))
            {//now we are certain we are in the right place
                LookUpEdit editor = sender as LookUpEdit;
                if (!((RPickListCollection)((BindingSource)editor.Properties.DataSource).DataSource).OfType<RPickList>().Any(a => a.RValue.Equals(e.NewValue)))
                {
                    repPatchNum1_ProcessNewValue(sender, new DevExpress.XtraEditors.Controls.ProcessNewValueEventArgs(e.NewValue));
                    vwSurfaceSoftware.SetRowCellValue(vwSurfaceSoftware.FocusedRowHandle, colPatchNum, e.NewValue);
                }
            }
        }
    }

    private void repPatchNum1_CloseUp(object sender, DevExpress.XtraEditors.Controls.CloseUpEventArgs e)
    {
        string surfaceSoftware = vwSurfaceSoftware.GetRowCellDisplayText(vwSurfaceSoftware.FocusedRowHandle, "SurfaceSoftware");
        if (string.Compare(surfaceSoftware, SOFTWARE_CHECK, true) == 0)
        {
            string version = vwSurfaceSoftware.GetRowCellDisplayText(vwSurfaceSoftware.FocusedRowHandle, "Version");
            if (version.ToLower().Contains(VERSION_CHECK))
            {//now we are certain we are in the right place
                LookUpEdit editor = sender as LookUpEdit;
                if (!((RPickListCollection)((BindingSource)editor.Properties.DataSource).DataSource).OfType<RPickList>().Any(a => a.RValue.Equals(e.Value)))
                {
                    e.Value = ((LookUpEdit)sender).Text;
                }
            }
        }
    }

    private void repPatchNum1_Closed(object sender, DevExpress.XtraEditors.Controls.ClosedEventArgs e)
    {
        string surfaceSoftware = vwSurfaceSoftware.GetRowCellDisplayText(vwSurfaceSoftware.FocusedRowHandle, "SurfaceSoftware");
        if (string.Compare(surfaceSoftware, SOFTWARE_CHECK, true) == 0)
        {
            string version = vwSurfaceSoftware.GetRowCellDisplayText(vwSurfaceSoftware.FocusedRowHandle, "Version");
            if (version.ToLower().Contains(VERSION_CHECK))
            {//now we are certain we are in the right place
                LookUpEdit editor = sender as LookUpEdit;
                string patch = vwSurfaceSoftware.GetRowCellValue(vwSurfaceSoftware.FocusedRowHandle, colPatchNum).ToString();
                if (String.IsNullOrEmpty(editor.Text) && !String.IsNullOrEmpty(patch))
                {
                    editor.Text = vwSurfaceSoftware.GetRowCellValue(vwSurfaceSoftware.FocusedRowHandle, colPatchNum).ToString();
                    vwSurfaceSoftware.UpdateCurrentRow();
                }
            }
        }
    }

至於最初的問題:如果您知道為什么會發生這種情況或如何防止這種情況發生,請發布答案。

謝謝大家:-)

我想我找到了一個更簡單的解決方法,在 DevExpress 13 上進行了測試。

當用戶按下 Tab/Enter 時,事件順序是 ProcessNewValue -> CloseUp

但是,如果用戶通過點擊其他地方完成查詢,事件是相反的:特寫鏡頭 - > ProcessNewValue和輸入的值丟失。 我們可以使用PopupCloseMode.Immediate(指定的下拉窗口被關閉,因為最終用戶點擊編輯器外)來檢測這種情況下,手動編輯需要輸入的值,將其設置為活動值字段和手動調用ProcessNewValue。 不需要其他事件。

private void myLookUp_CloseUp( object sender, CloseUpEventArgs e )
{
    var lookUpEdit = sender as LookUpEdit;
    if( lookUpEdit != null )
    {
        var enteredLookUpText = lookUpEdit.Text;
        if( e.CloseMode == PopupCloseMode.Immediate )
        {
            e.Value = enteredLookUpText;
            myLookUp_ProcessNewValue( sender, new ProcessNewValueEventArgs( enteredLookUpText ) );
        }
    }
    // Rest of event handler
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM