https://www.devexpress.com/Support/Center/Question/Details/T109932



다중선택 모드인 경우

몇 Row 선택후 Filtering 하게 되면 이전 선택정보를 잃어버리는데..

아래 처럼 하면 선택된 Row를 저장하게됨.

위 링크 참조 소스는 링크에서 맨 밑 첨부파일에서 발췌함.



void SubscribeEvents()

{    

          gridView1.MouseDown += new MouseEventHandler(gridView1_MouseDown);
            gridView1.MouseUp += new MouseEventHandler(gridView1_MouseUp);
            gridView1.ColumnFilterChanged += gridView1_ColumnFilterChanged;
        }

        void gridView1_ColumnFilterChanged(object sender, EventArgs e)
        {
            RestoreSelection(sender as GridView);
        }

        void RestoreSelection(GridView view)
        {
            BeginInvoke(new Action(() =>
            {
                for (int i = 0; i < selectedRows.Count; i++)
                    view.SelectRow(view.GetRowHandle(selectedRows[i]));
            }));
        }

        List<int> selectedRows = new List<int>();
        void gridView1_MouseUp(object sender, MouseEventArgs e)
        {
            GridView view = sender as GridView;
            RestoreSelection(view);
        }

        void gridView1_MouseDown(object sender, MouseEventArgs e)
        {
            GridView view = sender as GridView;
            GridHitInfo hi = view.CalcHitInfo(e.Location);
            if (hi.Column.FieldName == "DX$CheckboxSelectorColumn")
            {
                if (!hi.InRow)
                {
                    bool allSelected = view.DataController.Selection.Count == view.DataRowCount;
                    if (!allSelected)
                    {
                        for (int i = 0; i < view.RowCount; i++)
                        {
                            int sourceHandle = view.GetDataSourceRowIndex(i);
                            if (!selectedRows.Contains(sourceHandle))
                                selectedRows.Add(sourceHandle);
                        }
                    }
                    else selectedRows.Clear();
                }
                else
                {
                    int sourceHandle = view.GetDataSourceRowIndex(hi.RowHandle);
                    if (!selectedRows.Contains(sourceHandle))
                        selectedRows.Add(sourceHandle);
                    else
                        selectedRows.Remove(sourceHandle);
                }
            }
            RestoreSelection(view);
        }

반응형

+ Recent posts