Exemple #1
0
        void SelectNextViewRow(bool next)
        {
            var increment        = next ? 1 : -1;
            int?modelRowToSelect = null;              // If there are no selected rows, this is the default

            var rows = SelectedRows.ToArray();

            if (DataStoreView != null && rows.Length > 0)
            {
                // Get the last (or first, if moving back) selected view row.
                // This handles multiselection.
                int?currentRowViewIndex = null;
                foreach (var x in rows)
                {
                    var temp = DataStoreView.ModelToView(x);
                    if (temp != null &&
                        (currentRowViewIndex == null || Math.Sign(temp.Value - currentRowViewIndex.Value) == Math.Sign(increment)))
                    {
                        currentRowViewIndex = temp;
                    }
                }

                if (currentRowViewIndex != null)
                {
                    var newRow = currentRowViewIndex.Value + increment;                     // view index
                    if (newRow >= 0 &&
                        DataStore.Count > newRow)
                    {
                        modelRowToSelect = DataStoreView.ViewToModel(newRow);
                    }
                }
            }

            if (modelRowToSelect == null)
            {
                var viewRows = ViewRows.ToArray();
                if (viewRows.Length > 0)
                {
                    modelRowToSelect = next ? viewRows.First() : viewRows.Last();
                }
            }

            if (modelRowToSelect != null)
            {
                UnselectAll();
                SelectRow(modelRowToSelect.Value);
            }
        }
Exemple #2
0
        public void UnselectRow(int row)
        {
            ChangeSelection(() => {
                areAllObjectsSelected = false;
                if (selectedRows.Contains(row))
                {
                    selectedRows.Remove(row);
                }

                var viewIndex = DataStoreView.ModelToView(row);
                if (viewIndex != null)                 // can be null if the row is not in the view because it is filtered out
                {
                    Handler.UnselectRow(viewIndex.Value);
                }
            });
        }
Exemple #3
0
        /// <summary>
        /// Programmatically selects a row.
        /// </summary>
        public void SelectRow(int row)
        {
            ChangeSelection(() => {
                if (!AllowMultipleSelection)
                {
                    selectedRows.Clear();
                }

                selectedRows.Add(row);
                var viewIndex = DataStoreView.ModelToView(row);
                if (viewIndex != null)
                {
                    if (!AllowMultipleSelection)
                    {
                        Handler.UnselectAll();
                    }
                    Handler.SelectRow(viewIndex.Value);
                }
            });
        }