【问题标题】:Devexpress Repository ComboBoxEdit loosing cursor position. Edit.SelectionStart Not being assignedDevexpress Repository ComboBoxEdit 丢失光标位置。 Edit.SelectionStart 未分配
【发布时间】:2014-08-22 15:28:11
【问题描述】:

我在 gridcontrol 中的 comboBoxEdit 出现问题。我正在使用 Winforms Devepress 11.2。我单击了现有 Repository comboBoxEdit 的文本,然后输入了“向后显示”,但是,它像在镜子中一样显示为“sdrawkcab raeppa”。
有一些关于这个主题的帖子,但似乎没有一个解决方案有效

原因如下

 foreach (GridColumn column in this.gvNotes.Columns)
            {
                var columnEdit = column.ColumnEdit;
                if (columnEdit != null)
                {
                    column.ColumnEdit.EditValueChanged += this.PostEditValueChanged;

                }
            }
   private void PostEditValueChanged(object sender, EventArgs e)
        {
            this.gvNotes.PostEditor();

        }

此 PostEditor 确保当用户仍在当前单元格中时启用保存按钮。用户无需离开单元格或更改列即可将更改发布到网格。

这就是我所做的:

private void PostEditValueChanged(object sender, EventArgs e)
        {
            ComboBoxEdit edit = this.gridNotes.FocusedView.ActiveEditor as ComboBoxEdit;
            if (edit != null)
            {
                int len = edit.SelectionLength;
                int start = edit.SelectionStart;
                gridNotes.FocusedView.PostEditor();
                edit.SelectionLength = len;
                edit.SelectionStart = start;

            }

这并没有解决光标重置到起始位置的问题。 Edit.SelectionStart 未分配给 len 值。即使 len 更改为 1 edit.SelectionStart 仍为 0 有谁知道需要处理什么事件才能不松开光标位置?

【问题讨论】:

    标签: c# devexpress xtragrid


    【解决方案1】:

    这就是我所做的,似乎设置了插入符号的位置

    全局:私有 int carretPosition = 0;

     editvaluechanged handler
    
         SaveCaretPosition(editValue.ToString().Length);
                            this.gridView1.PostEditor();
                            this.gridView1.ShowEditor();
                            this.SetCaretPosition(this.gridView1.ActiveEditor as DevExpress.XtraEditors.TextEdit);
    
     private void SaveCaretPosition(int position)
            {
                carretPosition = position;
            }
    
            private void SetCaretPosition(TextEdit edit)
            {
                edit.SelectionStart = carretPosition;
            }
    

    【讨论】:

      猜你喜欢
      • 2012-09-13
      • 2021-04-01
      • 2019-01-25
      • 1970-01-01
      • 2019-10-02
      • 2016-05-07
      • 2013-07-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多