Devexpress Repository ComboBoxEdit loosing cursor position. Edit.SelectionStart Not being assigned

北城余情 提交于 2019-12-14 03:15:59

问题


I am having an issue with my comboBoxEdit in a gridcontrol. I am using Winforms Devepress 11.2. I clicked in the text of an existing Repository comboBoxEdit, and typed in "appear backwards", however, it displayed as "sdrawkcab raeppa" like it would in a mirror.
There are some posts about this topic but none of the solutions seem to work

The reason for this is the following

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

        }

This PostEditor ensures the save button is enabled when the user is still in the current cell. The user does not need to leave the cell or change column for the changes to be posted to the grid.

So this is what I did:

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;

            }

This did not solve the problem of the cursor resetting to the start position. Edit.SelectionStart is not being assinged to the len value.Even though len changes to 1 edit.SelectionStart remains at 0 Does anyone know what event needs to be handled to not loose the cursor position?


回答1:


This is what I did and seemed to set the caret position

global: private 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;
        }


来源:https://stackoverflow.com/questions/25450553/devexpress-repository-comboboxedit-loosing-cursor-position-edit-selectionstart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!