본문 바로가기

카테고리 없음

Devexpress Winform GridControl GridView 안에서 탭키로 EditAble.True 셀만을 이동

반응형

 

GridView EditAble.True 인 Cell간의 Tab키를 이용한 이동

 

public static void SetItemTabMove(this DevExpress.XtraGrid.Views.Grid.GridView gridView)
{
     gridView.KeyDown += (sender, e) =>
        {
            try
            {
                if (e.KeyCode == Keys.Enter)
                {
                    if (gridView.ActiveEditor == null)
                    {
                        gridView.ShowEditor();
                    }
                    else
                    {
                        gridView.CloseEditor();

                    }

                    var editor = gridView.ActiveEditor;
                    if (editor is SearchLookUpEdit searchLookUpEdit)
                    {
                        searchLookUpEdit.ShowPopup();
                    }

                    e.Handled = true;
                }
                else if (e.KeyCode == Keys.Tab)
                    {
                    bool isNewLine = false;

                SET:

                    foreach (var visibleColumn in gridView.Columns.Where(x => x.Visible).AsEnumerable())
                    {

                    }

                    var visibleColumns = gridView.Columns.Cast<DevExpress.XtraGrid.Columns.GridColumn>()
                                        .Where(x => x.Visible)
                                        .ToList();

                    for (   int i = gridView.FocusedColumn.VisibleIndex; i < visibleColumns.Count; i++)
                    { 

                        if (visibleColumns[i].Visible == true)
                        {
                            if (visibleColumns[i].OptionsColumn.AllowEdit == true)
                            {
                                //마무리
                                if (isNewLine == true)
                                {
                                    gridView.FocusedColumn = visibleColumns[i];
                                    isNewLine = false;
                                    e.Handled = true;
                                    break;
                                }
                                else
                                {
                                    if (gridView.FocusedColumn != visibleColumns[i])
                                    {
                                        gridView.FocusedColumn = visibleColumns[i];
                                        e.Handled = true;
                                        break;
                                    }
                                    else if (gridView.FocusedColumn == visibleColumns[i])
                                    {
                                        //다음컬럼있으면
                                        if (visibleColumns.Any(x => x.VisibleIndex == i + 1))
                                        {

                                            DevExpress.XtraGrid.Columns.GridColumn nextColumn = visibleColumns.First(x => x.VisibleIndex == i + 1);
                                            //마지막 포커스값이면
                                            if (visibleColumns.Last(x => x.Visible) == nextColumn && isNewLine == false)
                                            {
                                                if (nextColumn.OptionsColumn.AllowEdit == false)
                                                {
                                                    if (gridView.FocusedRowHandle == (gridView.DataRowCount - 1))
                                                    {
                                                        //다음로
                                                        gridView.FocusedRowHandle = 0;
                                                        gridView.FocusedColumn = visibleColumns.First(x => x.Visible);
                                                        isNewLine = true;
                                                        goto SET;
                                                    }
                                                    else
                                                    {
                                                        //다음로
                                                        gridView.FocusedRowHandle = gridView.FocusedRowHandle + 1;
                                                        gridView.FocusedColumn = visibleColumns.First(x => x.Visible);
                                                        isNewLine = true;
                                                        goto SET;
                                                    }

                                                }
                                            }
                                            else
                                            {
                                                //마지막로우
                                                if (visibleColumns.First(x => x.VisibleIndex == i) == visibleColumns.Last(x => x.Visible))
                                                {
                                                    if (isNewLine == false)
                                                    {

                                                        if (gridView.FocusedRowHandle == (gridView.DataRowCount - 1))
                                                        {
                                                            //다음로
                                                            gridView.FocusedRowHandle = 0;
                                                            gridView.FocusedColumn = visibleColumns.First(x => x.Visible);
                                                            isNewLine = true;
                                                            goto SET;
                                                        }
                                                        else
                                                        {
                                                            //다음로
                                                            gridView.FocusedRowHandle = gridView.FocusedRowHandle + 1;
                                                            gridView.FocusedColumn = visibleColumns.First(x => x.Visible);
                                                            isNewLine = true;
                                                            goto SET;
                                                        }
                                                    }
                                                }
                                                else
                                                {

                                                }
                                            }
                                        }
                                        else
                                        {
                                            //마지막 컬럼포커스값이면
                                            if (isNewLine == false)
                                            {

                                                if (gridView.FocusedRowHandle == (gridView.DataRowCount - 1))
                                                {
                                                    //다음로
                                                    gridView.FocusedRowHandle = 0;
                                                    gridView.FocusedColumn = visibleColumns.First(x => x.Visible);
                                                    isNewLine = true;
                                                    goto SET;
                                                }
                                                else
                                                {
                                                    //다음로
                                                    gridView.FocusedRowHandle = gridView.FocusedRowHandle + 1;
                                                    gridView.FocusedColumn = visibleColumns.First(x => x.Visible);
                                                    isNewLine = true;
                                                    goto SET;
                                                }
                                            }
                                            else
                                            {
                                                //마지막로우
                                                if (visibleColumns.First(x => x.VisibleIndex == i) == visibleColumns.Last(x => x.Visible))
                                                {
                                                    if (isNewLine == false)
                                                    {

                                                        if (gridView.FocusedRowHandle == (gridView.DataRowCount - 1))
                                                        {
                                                            //다음로
                                                            gridView.FocusedRowHandle = 0;
                                                            gridView.FocusedColumn = visibleColumns.First(x => x.Visible);
                                                            isNewLine = true;
                                                            goto SET;
                                                        }
                                                        else
                                                        {
                                                            //다음로
                                                            gridView.FocusedRowHandle = gridView.FocusedRowHandle + 1;
                                                            gridView.FocusedColumn = visibleColumns.First(x => x.Visible);
                                                            isNewLine = true;
                                                            goto SET;
                                                        }
                                                    }
                                                }
                                                else
                                                {

                                                }
                                            }
                                        }
                                    }

                                }

                            }
                            else
                            {
                                //마지막로우
                                if (visibleColumns.Last(x => x.Visible) == visibleColumns[i])
                                {
                                    if (isNewLine == false)
                                    {

                                        if (gridView.FocusedRowHandle == (gridView.DataRowCount - 1))
                                        {
                                            //다음로
                                            gridView.FocusedRowHandle = 0;
                                            gridView.FocusedColumn = visibleColumns.First(x => x.Visible);
                                            isNewLine = true;
                                            goto SET;
                                        }
                                        else
                                        {
                                            //다음로
                                            gridView.FocusedRowHandle = gridView.FocusedRowHandle + 1;
                                            gridView.FocusedColumn = visibleColumns.First(x => x.Visible);
                                            isNewLine = true;
                                            goto SET;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {

            }
        };

    }