示例#1
0
            /// <summary>
            /// Stores the selected rows.
            /// </summary>
            /// <param name="view">The grid view to store the selection for.</param>
            /// <remarks>This method will also store the selected cells when GridMultiSelectMode is set to CellSelect.</remarks>
            public void StoreSelection(GridView view)
            {
                //Clear any previously selected rows.
                SavedSelectionList.Clear();
                //Clear any previously selected cells.
                CellSelection.Clear();
                //Get the selected rows.
                var selectedRows = view.GetSelectedRows();
                //Are there any selected rows? If not, then we just have a single focused but not selected row.
                var focusedRowStored = false;

                if (selectedRows != null)
                {
                    //Go through each selected row in the grid view.
                    foreach (var selectedRowHandle in selectedRows)
                    {
                        //Add the selected row to the selection list.
                        var dataRowHandle = StoreSelectedRow(view, selectedRowHandle, selectedRowHandle == view.FocusedRowHandle, true);
                        // If focused row have been stored
                        if (!focusedRowStored && selectedRowHandle == view.FocusedRowHandle)
                        {
                            focusedRowStored = true;
                        }

                        //If GridMultiSelectMode is set to CellSelect then store selected cells.
                        if (view.OptionsSelection.MultiSelectMode == GridMultiSelectMode.CellSelect)
                        {
                            //Get the selected columns for the row handle.
                            var columns     = view.GetSelectedCells(dataRowHandle);
                            var columnNames = new string[columns.Length];
                            //Add the column names to the array.
                            for (var index = 0; index < columns.Length; index++)
                            {
                                columnNames[index] = columns[index].FieldName;
                            }
                            //Add or update the the cell selection for the row.
                            CellSelection[view.GetRowCellValue(dataRowHandle, _descriptor.KeyColumn)] = columnNames;
                        }
                    }
                }

                // Add the focused row to the selection.
                if (!focusedRowStored)
                {
                    StoreSelectedRow(view, view.FocusedRowHandle, true, false);
                }
            }
示例#2
0
            /// <summary>
            /// Adds the specified row to the selection list.
            /// </summary>
            /// <param name="view">The grid view that the row belongs to.</param>
            /// <param name="rowHandle">The row handle of the row to add.</param>
            /// <returns>Returns the row handle that was added.</returns>
            private int StoreSelectedRow(GridView view, int rowHandle, bool focused, bool selected)
            {
                // Create row info object.
                RowInfo rowInfo;

                rowInfo.Level          = view.GetRowLevel(rowHandle);
                rowInfo.SelectionType  = focused ? SelectionType.Focus : SelectionType.None;
                rowInfo.SelectionType |= selected ? SelectionType.Selection : SelectionType.None;
                // If the handle is a group row handle then replace rowHandle with the group row handles data row handle.
                if (rowHandle < 0) // group row
                {
                    rowHandle = view.GetDataRowHandleByGroupRowHandle(rowHandle);
                }

                // Store the value of the row handle in the row info object.
                rowInfo.Value = view.GetRowCellValue(rowHandle, _descriptor.KeyColumn);
                // Add the row info to the selection list.
                SavedSelectionList.Add(rowInfo);
                // Return the row handle.
                return(rowHandle);
            }