RepositoryItemLookupEdit新值在处理之前消失

时间:2014-02-07 21:27:20

标签: c# devexpress repositorylookupedit

我在网格中有一个需要能够接受新值的LookupEdit。当我输入新值并按“Enter”或“Tab”时,它会通过ProcessNewValue事件正常保存,但是当我输入一个值并单击网格中的其他位置,在另一个单元格或仅在空白区域中时,该值将完全消失。通过实现其他几个事件并设置断点,我发现在“CloseUp”事件触发之前该值消失了。验证,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();
                }
            }
        }
    }

关于原始问题:如果你知道为什么会发生这种情况或者如何预防,请发一个答案。

谢谢大家: - )

1 个答案:

答案 0 :(得分:0)

我想我找到了一个更简单的解决方法,在 DevExpress 13 上进行了测试。

当用户按下 Tab/Enter 时,事件顺序是 ProcessNewValue -> CloseUp

但是,如果用户通过单击其他位置完成查找,则事件会反转: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
}