简体   繁体   English

RepositoryItemLookupEdit 新值在处理前消失

[英]RepositoryItemLookupEdit new value disappears before being processed

I have a LookupEdit in the grid that needs to be able to accept new values.我在网格中有一个 LookupEdit 需要能够接受新值。 When I enter the new value and press "Enter" or "Tab", it saves normally via the ProcessNewValue event, however when I enter a value and click elsewhere in the grid, on another cell or just in white space, the value vanishes completely.当我输入新值并按“Enter”或“Tab”时,它会通过 ProcessNewValue 事件正常保存,但是当我输入一个值并单击网格中的其他地方、另一个单元格或仅在空白处时,该值完全消失. By implementing several other events and setting breakpoints all I figured out was that the value disappears before the "CloseUp" event fires.通过实现其他几个事件并设置断点,我发现该值在“CloseUp”事件触发之前消失了。 Validating, EditValueChanged, EditValueChanging, ProcessNewValue, Closed, Leave, and even GetNotInListValue never even get called because of the empty value. Validating、EditValueChanged、EditValueChanging、ProcessNewValue、Closed、Leave 甚至 GetNotInListValue 都不会因为空值而被调用。

Can anyone think of some setting I haven't found yet, or any other reason why this value would disappear...And how I might stop it from happening?谁能想到一些我还没有找到的设置,或者这个值会消失的任何其他原因......以及我如何阻止它发生?

Found a valid Workaround找到了有效的解决方法

I implemented the following 3 events, in sequence, to solve this issue.我依次实现了以下 3 个事件来解决这个问题。 I still have no idea what caused it, or how to go about preventing it.我仍然不知道是什么导致了它,或者如何去预防它。 This is a Workaround , not a solution, and should be treated as such.这是一种解决方法,而不是解决方案,应如此对待。 I end up having to manually call the ProcessNewValue method, as well as forcing the value to equal the text field, and the text field back into the value later on.我最终不得不手动调用ProcessNewValue方法,并强制该值等于文本字段,稍后将文本字段返回到该值。 Not the smoothest of operations, but it does work.不是最顺畅的操作,但它确实有效。

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();
                }
            }
        }
    }

As to the original question: Please post an answer if you know why this might be happening or how to prevent it.至于最初的问题:如果您知道为什么会发生这种情况或如何防止这种情况发生,请发布答案。

Thanks all :-)谢谢大家:-)

I think I found a simpler workaround, tested on DevExpress 13.我想我找到了一个更简单的解决方法,在 DevExpress 13 上进行了测试。

When user presses Tab/Enter, event sequence is ProcessNewValue -> CloseUp当用户按下 Tab/Enter 时,事件顺序是 ProcessNewValue -> CloseUp

However if user finishes lookup by clicking somewhere else, events are reversed: CloseUp -> ProcessNewValue and entered value is lost.但是,如果用户通过点击其他地方完成查询,事件是相反的:特写镜头 - > ProcessNewValue和输入的值丢失。 We can use PopupCloseMode.Immediate (specifies that the dropdown window was closed because an end-user clicked outside the editor) to detect this case, manually take entered value from editor, set it to event Value field and manually call ProcessNewValue.我们可以使用PopupCloseMode.Immediate(指定的下拉窗口被关闭,因为最终用户点击编辑器外)来检测这种情况下,手动编辑需要输入的值,将其设置为活动值字段和手动调用ProcessNewValue。 No need for other events.不需要其他事件。

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