Example #1
0
        private string RowIndex(int index) // функция для вывода ячейки выбранной строки в таблице
        {
            var ci      = new DataGridCellInfo(StudentGrid.SelectedItem, StudentGrid.Columns[index]);
            var content = ci.Column.GetCellContent(ci.Item) as TextBlock;

            return(content.Text); // возвращаем значение заданной ячейки таблицы
        }
Example #2
0
        private void dg_Bules_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            DataGridCellInfo Cell = ((System.Windows.Controls.DataGrid)(e.Source)).CurrentCell;

            if (Cell == null || Tubes == null || Cell.Column == null || Cell.Item == null)
            {
                return;
            }
            if (Tubes.Rows.Count == 0)
            {
                return;
            }
            int ColumnIndex = CommFuntion.GetDataGridCellColumnIndex(Cell);
            int RowIndex    = CommFuntion.GetDataGridCellRowIndex(Cell) - 1;

            if (Tubes.Rows[RowIndex]["TubeType" + ColumnIndex.ToString()].ToString() == "-1")
            {
                MessageBox.Show("当前位置没有采血管!", "系统提示");
                return;
            }
            TubeBarCodeEdit _TubeBarCodeEdit = new TubeBarCodeEdit();

            _TubeBarCodeEdit.Cell = ((System.Windows.Controls.DataGrid)(e.Source)).CurrentCell;
            if ((Boolean)_TubeBarCodeEdit.ShowDialog())
            {
                Tubes.Rows[RowIndex]["BarCode" + ColumnIndex.ToString()] = _TubeBarCodeEdit.txt_BarCode.Text;
            }
        }
Example #3
0
        private void DelTypeBtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int row = InsTypeDG.SelectedIndex;

                if (row != -1)
                {
                    var    ci   = new DataGridCellInfo(InsTypeDG.Items[row], InsTypeDG.Columns[0]);
                    var    crow = ci.Column.GetCellContent(ci.Item) as TextBlock;
                    string vrow = crow.Text;

                    var instype = unitOfWork.InsTypeRepository.Entities
                                  .FirstOrDefault(p => p.Type == vrow);
                    unitOfWork.InsTypeRepository.Remove(instype);
                    unitOfWork.Commit();
                    MessageBox.Show("Тип страховки успешно удален");
                    UpdateInsTypeDG();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #4
0
        private void DelIncBtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int row = IncidentsDG.SelectedIndex;

                if (row != -1)
                {
                    var ci   = new DataGridCellInfo(IncidentsDG.Items[row], IncidentsDG.Columns[0]);
                    var crow = ci.Column.GetCellContent(ci.Item) as TextBlock;
                    int vrow = Convert.ToInt32(crow.Text);

                    var incident = unitOfWork.IncidentRepository.Entities
                                   .FirstOrDefault(p => p.IdIncident == vrow);
                    unitOfWork.IncidentRepository.Remove(incident);
                    unitOfWork.Commit();
                    MessageBox.Show("Страховой случай удален");
                    UpdateIncidentDG();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void dataGridView3_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                DataGridCellInfo cell0 = dataGridView3.SelectedCells[0];
                primary = Convert.ToInt32(((TextBlock)cell0.Column.GetCellContent(cell0.Item)).Text);

                DataGridCellInfo cell1 = dataGridView3.SelectedCells[1];
                Nom_client.Text = ((TextBlock)cell1.Column.GetCellContent(cell1.Item)).Text;

                DataGridCellInfo cell3 = dataGridView3.SelectedCells[2];
                date_facture.Text = ((TextBlock)cell3.Column.GetCellContent(cell3.Item)).Text;

                msh.LoadData(
                    "SELECT * FROM `details`, `article` Where article.N_Article = details.N_Article and details.N_Fact = '" +
                    primary + "'",
                    dataGridView4);
                TTC_global.Text = msh.getValue("select ttc_global from facture where N_Fact = '" + primary + "'",
                                               "ttc_global");
            }
            catch (Exception)
            {
                //   MessageBox.Show(ex.Message);
            }
        }
Example #6
0
        private void DeleteCategory_Click(object sender, RoutedEventArgs e)
        {
            if (CategoriesDataGrid.SelectedIndex != -1)
            {
                CustomMessageBox cmb = new CustomMessageBox((int)MessageBoxColorTypes.yellow, "Sunteti sigur ca doriti sa eliminati categoria selectata?", this, MessageBoxButton.YesNo);

                if (cmb.ShowDialog() == true)
                {
                    DataGridCellInfo cellInfo = CategoriesDataGrid.SelectedCells[0];

                    int id = int.Parse((cellInfo.Column.GetCellContent(cellInfo.Item) as TextBlock).Text);

                    if (DeleteCategory(id))
                    {
                        CustomMessageBox c = new CustomMessageBox((int)MessageBoxColorTypes.green, "Categoria a fost eliminata cu succes!", this, MessageBoxButton.OK);
                        c.ShowDialog();
                    }
                    else
                    {
                        CustomMessageBox c = new CustomMessageBox((int)MessageBoxColorTypes.red, "A aparut o eroare, daca problema persista va rugam sa contactati un administrator!", this, MessageBoxButton.OK);
                        c.ShowDialog();
                    }
                }
            }
            else
            {
                CustomMessageBox cmb = new CustomMessageBox((int)MessageBoxColorTypes.red, "Va rugam sa selectati o categorie!", this, MessageBoxButton.OK);
                cmb.ShowDialog();
            }
        }
Example #7
0
        private void dgChild_RowEditEnding_1(object sender, DataGridRowEditEndingEventArgs e)
        {
            if (e.EditAction == DataGridEditAction.Cancel)
            {
                e.Cancel = true;
                return;
            }
            var f = DataContext as Family;
            var x = e.Row.DataContext as FamilyPerson;

            if (x != null && f != null)
            {
                if (!x.IsValidate())
                {
                    e.Cancel = true;
                }
                else
                {
                    dgChild.SelectedCells.Clear();
                    var dgc = new DataGridCellInfo(dgChild.Items[dgChild.Items.Count - 1], dgChild.Columns[1]);
                    dgChild.SelectedCells.Add(dgc);
                    dgChild.CurrentCell = dgc;
                }
            }
        }
Example #8
0
 /// <summary>
 /// 表格响应按键事件
 /// </summary>
 private void Dg_PreviewKeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Enter)
     {
         int rowIndex = this.dg.SelectedIndex;
         DataGridCellInfo cellInfo = this.dg.CurrentCell;
         if (null != cellInfo && null != cellInfo.Column)
         {
             if (rowIndex == this.dg.Items.Count - 1 && cellInfo.Column.DisplayIndex == this.dg.Columns.Count - 1)
             {
                 // 在最后一个单元格点击回车进入搜索框
                 e.Handled             = true;
                 this.dg.SelectedIndex = -1;
                 this.ResetSearchBoxFocus();
             }
             else if (rowIndex > -1 && cellInfo.Column.DisplayIndex == 0)
             {
                 // 第一列,删除事件
                 e.Handled = true;
                 this.ButtonDeleteItem_Click(null, null);
                 // 焦点定位到
                 DataGridCell timeCell = DataGridStyle.GetCell(this.dg, this.dg.SelectedIndex, 2);
                 if (timeCell != null)
                 {
                     this.dg.CurrentCell = new DataGridCellInfo(timeCell);
                     this.dg.BeginEdit();
                 }
             }
         }
     }
 }
        private void DataGridExt_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
        {
            var cell = e.NewFocus as DataGridCell;

            if (cell != null)
            {
                if (_needUpdateSelectedIndexInGotFocusEvent)
                {
                    _needUpdateSelectedIndexInGotFocusEvent = false;

                    var index = Items.IndexOf(CurrentCell.Item);
                    if (SelectedIndex != index)
                    {
                        SelectedIndex = index;
                    }
                }
                else if (_needUpdateCurrentCellInGotFocusEvent == true)
                {
                    _needUpdateCurrentCellInGotFocusEvent = false;

                    if ((SelectedIndex < Items.Count - 1) && SelectedIndex > 0)
                    {
                        var index = Items.IndexOf(CurrentCell.Item);
                        if (SelectedIndex != index)
                        {
                            CurrentCell = new DataGridCellInfo(Items[SelectedIndex], Columns[1]);
                        }
                    }
                }
            }
        }
Example #10
0
        private void SearchBox_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Down)
            {
                MasterDataGrid.Focus();
                //then create a new cell info, with the item we wish to edit and the column number of the cell we want in edit mode
                var cellInfo = new DataGridCellInfo(MasterDataGrid.Items[0], MasterDataGrid.Columns[0]);
                //set the cell to be the active one
                MasterDataGrid.CurrentCell = cellInfo;
                //scroll the item into view
                MasterDataGrid.ScrollIntoView(MasterDataGrid.Items[0]);
                //begin the edit
                MasterDataGrid.BeginEdit();
            }

            if (e.Key == Key.Up)
            {
                MasterDataGrid.Focus();
                //then create a new cell info, with the item we wish to edit and the column number of the cell we want in edit mode
                var cellInfo = new DataGridCellInfo(MasterDataGrid.Items[MasterDataGrid.Items.Count - 1],
                                                    MasterDataGrid.Columns[0]);
                //set the cell to be the active one
                MasterDataGrid.CurrentCell = cellInfo;
                //scroll the item into view
                MasterDataGrid.ScrollIntoView(MasterDataGrid.Items[MasterDataGrid.Items.Count - 1]);
                //begin the edit
                MasterDataGrid.BeginEdit();
            }
        }
Example #11
0
        protected override void OnPreviewMouseLeftButtonDown(System.Windows.Input.MouseButtonEventArgs e)
        {
            base.OnPreviewMouseLeftButtonDown(e);

            DataGridRow rowOwner      = DataGridRowOwner;
            DataGrid    dataGridOwner = rowOwner != null ? rowOwner.DataGridOwner : null;

            if ((dataGridOwner != null) && (rowOwner != null))
            {
                DataGridCellInfo previousCell = dataGridOwner.CurrentCell;
                dataGridOwner.HandleSelectionForRowHeaderAndDetailsInput(rowOwner, /* startDragging = */ true);

                // HandleSelectionForRowHeaderAndDetailsInput above sets the CurrentCell
                // of datagrid to the cell with displayindex 0 in the row.
                // This implicitly queues a request to MakeVisible command
                // of ScrollViewer. The command handler calls MakeVisible method of
                // VirtualizingStackPanel (of rows presenter) which works only
                // when the visual's parent layout is clean. DataGridCellsPanel layout is
                // not clean as per MakeVisible of VSP becuase we distribute the layout of cells for the
                // sake of row headers and hence it fails. VSP.MakeVisible method requeues a request to
                // ScrollViewer.MakeVisible command hence resulting into an infinite loop.
                // The workaround is to bring the concerned cell into the view by calling
                // ScrollIntoView so that by the time MakeVisible handler of ScrollViewer is
                // executed the cell is already visible and the handler succeeds.
                DataGridCellInfo currentCell = dataGridOwner.CurrentCell;
                if (currentCell != previousCell && currentCell != DataGridCellInfo.Unset)
                {
                    dataGridOwner.ScrollIntoView(currentCell.Item, currentCell.Column);
                }
            }
        }
Example #12
0
        protected override void OnCurrentCellChanged(EventArgs e)
        {
            if (justCommitted)
            {
                justCommitted = false;

                object itemToSelect = CurrentItem;

                if (this.CurrentCell.Column != null && (this.CurrentCell.Column.Header.ToString() == "Interest Rate" || this.CurrentCell.Column.Header.ToString() == "Transaction Amount"))
                {
                    //first focus the grid
                    Focus();
                    //then create a new cell info, with the item we wish to edit and the column number of the cell we want in edit mode
                    DataGridCellInfo cellInfo = new DataGridCellInfo(itemToSelect, Columns[0]);
                    //set the cell to be the active one
                    CurrentCell = cellInfo;
                    //scroll the item into view
                    ScrollIntoView(itemToSelect);
                    //begin the edit
                    BeginEdit();
                }
            }



            base.OnCurrentCellChanged(e);
        }
Example #13
0
        private void Mi_reject_Click(object sender, RoutedEventArgs e)
        {
            try {
                DataGrid r       = (DataGrid)this.FindName("RegisterGrid");
                var      index_r = r.SelectedIndex;

                //Получение номера паспорта пациента
                var passport_r = new DataGridCellInfo(RegisterGrid.Items[index_r], RegisterGrid.Columns[2]);
                var content_r  = passport_r.Column.GetCellContent(passport_r.Item) as TextBlock;

                //Получение даты и времени
                var date_t       = new DataGridCellInfo(RegisterGrid.Items[index_r], RegisterGrid.Columns[0]);
                var content_date = date_t.Column.GetCellContent(date_t.Item) as TextBlock;

                string passport = content_r.Text;
                string dateTime = content_date.Text;

                //Запрос
                string Answer = new WebClient().DownloadString(DataValue.Url + "Code/reject_user.php?" + "passportNumber=" + passport + "&dateTime=" + dateTime);

                //Обновление DataGrid
                update_datagrid();
            }
            catch (Exception ex) { };
        }
        public ChooseCategory(DataGridCellInfo cellInfo, IEnumerable <Category> categories)
        {
            InitializeComponent();

            _cellInfo   = cellInfo;
            _categories = categories;

            int?selectedCategory = 0;

            if (((DataRowView)cellInfo.Item).Row.ItemArray[4] != null)
            {
                selectedCategory = (int?)((DataRowView)cellInfo.Item).Row.ItemArray[4];
            }
            RadioButton radioButton;

            foreach (var category in categories)
            {
                radioButton         = new RadioButton();
                radioButton.Content = category.Name;
                if (selectedCategory != null && category.Id == selectedCategory)
                {
                    radioButton.IsChecked = true;
                }
                StackPanel.Children.Add(radioButton);
            }
        }
 /// <summary>
 /// Raises the System.Windows.Controls.DataGrid.SelectedCellsChanged event.
 /// </summary>
 /// <param name="e">The data for the event.</param>
 protected override void OnSelectedCellsChanged(SelectedCellsChangedEventArgs e)
 {
     // base.OnSelectedCellsChanged(e);
     if (e.AddedCells != null && e.AddedCells.Count == 1)
     {
         DataGridCellInfo cellInfo = e.AddedCells[0];
         if (!cellInfo.IsValid)
         {
             return;
         }
         FrameworkElement cellContent = cellInfo.Column.GetCellContent(cellInfo.Item);
         if (cellContent == null)
         {
             return;
         }
         DataGridCell dataGridCell = (DataGridCell)cellContent.Parent;
         if (dataGridCell == null)
         {
             return;
         }
         Point relativePoint = dataGridCell.TransformToAncestor(this).Transform(new Point(0, 0));
         Point startPosition = new Point(relativePoint.X - 3, relativePoint.Y - 3);
         Point endPosition   = new Point(relativePoint.X + dataGridCell.ActualWidth, relativePoint.Y + dataGridCell.ActualHeight);
         UpdateSelectionRectangle(startPosition, endPosition);
     }
 }
Example #16
0
        private void dataViewOV_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            DataGridCellInfo cell0 = dataViewOV.SelectedCells[0];

            tempNumOV = int.Parse(((TextBlock)cell0.Column.GetCellContent(cell0.Item)).Text);

            string          query = "select * from ov where NumPayement='" + NumPayement + "' and NumVerssement='" + tempNumOV + "'";
            MySqlDataReader rdr   = null;
            MySqlConnection con   = null;
            MySqlCommand    cmd   = null;

            con = new MySqlConnection(Database.ConnectionString());
            con.Open();
            cmd            = new MySqlCommand(query);
            cmd.Connection = con;
            rdr            = cmd.ExecuteReader();
            bool oneTime = true;

            while (rdr.Read())
            {
                tempNumVerssement          = int.Parse(rdr["NumVerssement"].ToString());
                inputNumOV.Text            = rdr["NumOV"].ToString();
                inputDateVersement.Text    = rdr["DateOV"].ToString();
                inputDateEcheance.Text     = rdr["DateEcheance"].ToString();
                inputMontant.Text          = rdr["MontantAV"].ToString();
                inputEtat.Text             = rdr["Etat"].ToString();
                inputDateRecu.Text         = rdr["DateRecu"].ToString();
                inputNumRecu.Text          = rdr["NumRecu"].ToString();
                inputTypePayement.Text     = rdr["TypePayement"].ToString();
                inputNaturePayement.Text   = rdr["NaturePayement"].ToString();
                inputNatureFrais.Text      = rdr["NatureFrais"].ToString();
                inputNumPayement.IsEnabled = inputNumOV.IsEnabled = inputDateVersement.IsEnabled = inputDateEcheance.IsEnabled = inputMontant.IsEnabled = false;
                BtnOV.IsEnabled            = false;
            }
        }
Example #17
0
        public string GetSelectedCellValue()
        {
            DataGridCellInfo cellInfo = AssetListSelect.SelectedCells[0];

            if (cellInfo == null)
            {
                return(null);
            }

            DataGridBoundColumn column = cellInfo.Column as DataGridBoundColumn;

            if (column == null)
            {
                return(null);
            }

            FrameworkElement element = new FrameworkElement()
            {
                DataContext = cellInfo.Item
            };

            BindingOperations.SetBinding(element, TagProperty, column.Binding);

            return(element.Tag.ToString());
        }
Example #18
0
        // The user has selected a row. Get the metadata from that row, and display the metadata name.
        private void Datagrid_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
        {
            IList <DataGridCellInfo> selectedcells = e.AddedCells;

            // Make sure there are actually some selected cells
            if (selectedcells == null || selectedcells.Count == 0)
            {
                return;
            }

            // We should only have a single selected cell, so just grab the first one
            DataGridCellInfo di = selectedcells[0];

            // the selected item is the entire row, where the format returned is [MetadataName , MetadataValue]
            // Parse out the metadata name and display it
            String[] s = di.Item.ToString().Split(',');  // Get the "[Metadataname" portion before the ','

            this.metadataName = s[0].Substring(1);       // Remove the leading '[' or '('
            if (this.metadataDictionary.ContainsKey(this.metadataName))
            {
                this.MetadataDisplayText.Text    = this.metadataDictionary[this.metadataName].Name;
                this.MetadataDisplayText.ToolTip = this.MetadataDisplayText.Text;
            }
            else
            {
                this.MetadataDisplayText.Text    = String.Empty;
                this.MetadataDisplayText.ToolTip = String.Empty;
            }
        }
Example #19
0
        public bool SetFocusOnSelectedRow(object selected, string columnHeader)
        {
            if ((this.ParentMenu != null && this.ParentMenu.IsOpen) ||
                (this.ContextMenu != null && this.ContextMenu.IsOpen))
            {
                // fix bug where context menu disappears when you right click on a new item.
                return(false);
            }
            // the focus this row so that user can continue using keyboard navigation
            DataGridRow row = this.ItemContainerGenerator.ContainerFromItem(selected) as DataGridRow;

            if (row != null)
            {
                int columnToFocus = GetColumnIndexByTemplateHeader(columnHeader);
                if (columnToFocus < 0)
                {
                    return(false);
                }
                DataGridCellInfo dgci = this.SelectedCells[columnToFocus];
                if (dgci != null)
                {
                    int rowIndex = row.GetIndex();
                    int colIndex = GetColIndex(dgci);
                    row.ApplyTemplate();
                    DataGridCell dgc = GetCell(rowIndex, colIndex);
                    if (dgc != null)
                    {
                        dgc.Focus();
                        return(true);
                    }
                }
            }
            return(false);
        }
        /// <summary>
        /// Called when [preview mouse left button down].
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void OnPreviewMouseLeftButtonDown(object sender, RoutedEventArgs e)
        {
            var cell = sender as DataGridCell;

            if (cell != null && !cell.IsEditing && !cell.IsReadOnly)
            {
                if (cell.Column != null && cell.Column.DisplayIndex > 0)
                {
                    return;
                }

                var parentRow = cell.Parent as DataGridRow;
                if (parentRow != null)
                {
                    SelectedIndex = parentRow.GetIndex();
                }

                CurrentCell = new DataGridCellInfo(cell);
                BeginEdit(e);
                var cb = FindVisualChild <CheckBox>(cell);

                if (cb == null)
                {
                    return;
                }

                //var cb = (CheckBox) obj;
                cb.Focus();
                cb.IsChecked = !cb.IsChecked;
            }
        }
Example #21
0
        //Add to foodDiary click event
        private void Button_Click_Add(object sender, RoutedEventArgs e)
        {
            //Make submit box invisible
            inputstack.Visibility = Visibility.Collapsed;

            //Sql Connection String
            SqlConnection con = new SqlConnection(Properties.Settings.Default.GeneratePath());

            //Open Connection
            con.Open();
            //Get Selected Cell Data as string Foodname
            DataGridCellInfo cell     = datasearch.SelectedCells[0];
            String           Foodname = ((TextBlock)cell.Column.GetCellContent(cell.Item)).Text;

            // Sql string to get FoodID
            string sqlFID = "SELECT FoodID FROM [DATA.AP] WHERE [Food Name] = '" + Foodname + "'";
            //Create Sql command and Execute
            SqlCommand cmdFID = new SqlCommand(sqlFID, con);
            String     FoodID = (string)cmdFID.ExecuteScalar();
            //string for amount column
            string amount = tbxamount.Text;
            // sql string to add data to userdiary table
            string sqladd = "INSERT INTO UserDiary(UserID, FoodID, Amount) VALUES ('" + UserID + "', '" + FoodID + "', '" + amount + "' )";

            //create and run sql command to add data to userdiary
            SqlCommand cmd = new SqlCommand(sqladd, con);

            cmd.ExecuteNonQuery();
            //run FoodDiaryIni Method
            FoodDiaryIni();
            //run ExpandedfoodDiary Method
            Expandedfooddiary();
            //Close Connection
            con.Close();
        }
        private PointInt GetCellPositionFromCellInfo(DataGridCellInfo cellInfo)
        {
            int rowIndex    = grid.Items.IndexOf(cellInfo.Item);
            int columnIndex = grid.Columns.IndexOf(cellInfo.Column);

            return(new PointInt(columnIndex, rowIndex));
        }
Example #23
0
        private void stopUpdatableAttributesDataGrid_CanExecuteRoutedEventHandler(object sender, CanExecuteRoutedEventArgs e)
        {
            var cells = stopUpdatableAttributesDataGrid.SelectedCells;

            // supporting paste operation into only one selected cell
            if (cells.Count != 1)
            {
                e.CanExecute = false;
                return;
            }

            // don't allow to edit the first column
            DataGridCellInfo cellInfo = cells[0];

            if (cellInfo == null || cellInfo.Column.DisplayIndex < 1)
            {
                e.CanExecute = false;
                return;
            }

            ItemAttribute item = cellInfo.Item as ItemAttribute;

            if (item == null)
            {
                e.CanExecute = false;
                return;
            }

            e.CanExecute = Clipboard.ContainsText();
        }
Example #24
0
        private void button3_Click_1(object sender, RoutedEventArgs e)
        {
            dataGrid1.ItemsSource = "";
            if (dataGrid2.Items.Count > 0)
            {
                for (int i = 0; i < dataGrid2.Items.Count; i++)
                {
                    DataGridCellInfo dir2 = new DataGridCellInfo(dataGrid2.Items[i], dataGrid2.Columns[0]);
                    var chb = dir2.Column.GetCellContent(dir2.Item) as CheckBox;
                    if (chb.IsChecked == true)
                    {
                        DataGridCellInfo inamed      = new DataGridCellInfo(dataGrid2.Items[i], dataGrid2.Columns[1]);
                        DataGridCellInfo iname       = new DataGridCellInfo(dataGrid2.Items[i], dataGrid2.Columns[2]);
                        DataGridCellInfo iday        = new DataGridCellInfo(dataGrid2.Items[i], dataGrid2.Columns[3]);
                        DataGridCellInfo itime_start = new DataGridCellInfo(dataGrid2.Items[i], dataGrid2.Columns[4]);
                        DataGridCellInfo itime_end   = new DataGridCellInfo(dataGrid2.Items[i], dataGrid2.Columns[5]);
                        DataGridCellInfo itype       = new DataGridCellInfo(dataGrid2.Items[i], dataGrid2.Columns[6]);
                        DataGridCellInfo iaddress    = new DataGridCellInfo(dataGrid2.Items[i], dataGrid2.Columns[7]);
                        DataGridCellInfo iteacher    = new DataGridCellInfo(dataGrid2.Items[i], dataGrid2.Columns[8]);
                        var name       = iname.Column.GetCellContent(iname.Item) as TextBlock;
                        var named      = inamed.Column.GetCellContent(iname.Item) as TextBlock;
                        var day        = iday.Column.GetCellContent(iday.Item) as TextBlock;
                        var time_start = itime_start.Column.GetCellContent(itime_start.Item) as TextBlock;
                        var time_end   = itime_end.Column.GetCellContent(itime_end.Item) as TextBlock;
                        var type       = itype.Column.GetCellContent(itype.Item) as TextBlock;
                        var address    = iaddress.Column.GetCellContent(iaddress.Item) as TextBlock;
                        var teacher    = iteacher.Column.GetCellContent(iteacher.Item) as TextBlock;
                        // result.Add(new Lesson(named.Text, name.Text, day.Text, time_start.Text, time_end.Text, type.Text, address.Text, teacher.Text));
                    }
                }

                dataGrid1.ItemsSource = result;
            }
        }
 public AbstractComponentData GetData()
 {
     if (grid.SelectedCells.Count == 0)
     {
         return(null);
     }
     else if (grid.SelectedCells.Count == 1)
     {
         DataGridCellInfo         cellInfo = grid.SelectedCells[0];
         SpreadsheetComponentCell cell     = cellInfo.Column.GetCellContent(cellInfo.Item) as SpreadsheetComponentCell;
         return(cell.data);
     }
     else
     {
         PointInt rangeStart = new PointInt(grid.Columns.Count, grid.Items.Count);
         PointInt rangeEnd   = new PointInt(-1, -1);
         foreach (DataGridCellInfo cellInfo in grid.SelectedCells)
         {
             PointInt position = GetCellPositionFromCellInfo(cellInfo);
             rangeStart.X = Math.Min(rangeStart.X, position.X);
             rangeStart.Y = Math.Min(rangeStart.Y, position.Y);
             rangeEnd.X   = Math.Max(rangeEnd.X, position.X);
             rangeEnd.Y   = Math.Max(rangeEnd.Y, position.Y);
         }
         string startId = data.cells[rangeStart.Y][rangeStart.X].id;
         string endId   = data.cells[rangeEnd.Y][rangeEnd.X].id;
         SpreadsheetRangeData rangeData = new SpreadsheetRangeData(this.valueStore, this.data, startId, endId);
         return(rangeData);
     }
 }
        private void dgTrainees_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
            if (e.EditAction == DataGridEditAction.Cancel)
            {
                e.Cancel = true;
                return;
            }
            var t  = DataContext as Training;
            var tt = e.Row.DataContext as Trained;

            if (tt != null && t != null)
            {
                if (!tt.IsValidate())
                {
                    e.Cancel = true;
                }
                else
                {
                    dgTrainees.SelectedCells.Clear();
                    var dgc = new DataGridCellInfo(dgTrainees.Items[dgTrainees.Items.Count - 1], dgTrainees.Columns[1]);
                    dgTrainees.SelectedCells.Add(dgc);
                    dgTrainees.CurrentCell = dgc;
                }
            }
        }
Example #27
0
        public string GetSelectedCellValue()
        {
            try
            {
                DataGridCellInfo cellInfo = dataGrid.SelectedCells[0];
                if (cellInfo == null)
                {
                    return(null);
                }

                DataGridBoundColumn column = cellInfo.Column as DataGridBoundColumn;
                if (column == null)
                {
                    return(null);
                }

                FrameworkElement element = new FrameworkElement()
                {
                    DataContext = cellInfo.Item
                };
                BindingOperations.SetBinding(element, TagProperty, column.Binding);

                return(element.Tag.ToString());
            }
            catch
            {
                MessageBox.Show("Please select a valid field.");
                return(null);
            }
        }
Example #28
0
        private Color GetCellBackground(int rowIndex, int colIndex)
        {
            object      item = theGrid.Items[rowIndex];
            DataGridRow row  = theGrid.ItemContainerGenerator.ContainerFromIndex(rowIndex) as DataGridRow;

            if (row == null)
            {
                theGrid.ScrollIntoView(item);
                row = theGrid.ItemContainerGenerator.ContainerFromIndex(rowIndex) as DataGridRow;
            }
            if (row != null)
            {
                DataGridCell cell = GetCell(theGrid, row, colIndex);
                if (cell != null)
                {
                    DataGridCellInfo dataGridCellInfo = new DataGridCellInfo(cell);
                    //theGrid.SelectedCells.Add(dataGridCellInfo);
                    if (cell.Background is SolidColorBrush s)
                    {
                        return(s.Color);
                    }
                }
            }
            return(Colors.White);
        }
Example #29
0
        private void dataViewML_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            DataGridCellInfo cell0 = dataViewVSP.SelectedCells[0];

            tempCodeVSP = int.Parse(((TextBlock)cell0.Column.GetCellContent(cell0.Item)).Text);

            string          query = "select * from vsp where CodeVSP='" + tempCodeVSP + "'";
            MySqlDataReader rdr   = null;
            MySqlConnection con   = null;
            MySqlCommand    cmd   = null;

            con = new MySqlConnection(Database.ConnectionString());
            con.Open();
            cmd            = new MySqlCommand(query);
            cmd.Connection = con;
            rdr            = cmd.ExecuteReader();
            bool oneTime = true;

            while (rdr.Read())
            {
                inputCodeVSP.Text    = rdr["CodeVSP"].ToString();
                inputDateetabli.Text = rdr["DateEtabliVSP"].ToString();
                inputDateEnreg.Text  = rdr["DateVSP"].ToString();
                inputNumVSP.Text     = rdr["NumVSP"].ToString();
                inputCodeP.Text      = rdr["RefP"].ToString();
                inputEtatVSP.Text    = rdr["Etat"].ToString();
                inputNotaire.Text    = rdr["NomNotaire"].ToString();
                inputadrNotaire.Text = rdr["AdresseNotaire"].ToString();
            }
            inputDateEnreg.IsEnabled = inputNumVSP.IsEnabled = IsEnabled;
            BtnDec.IsEnabled         = inputCodeP.IsEnabled = inputCodeVSP.IsEnabled = false;
        }
        private async void DataGridProgProcess_MouseDoubleClickAsync(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (e.ChangedButton != System.Windows.Input.MouseButton.Left)
            {
                return;
            }
            DataGridCellInfo cell = (sender as DataGrid).CurrentCell;

            if (cell.Column == null)
            {
                return;
            }
            if (cell.Column.DisplayIndex == ProgViewModel.N_JLinkSN || cell.Column.DisplayIndex == ProgViewModel.N_TimeEscape)
            {
                string jlink = (cell.Item as ProgViewModel.ProgProcess).Steps[ProgViewModel.N_JLinkSN].Text;
                if (!this.progTaskStatusList.Contains(jlink))
                {
                    this.view.Running = true;
                    this.progTaskStatusList.Add(jlink);
                    this.progProcessList[jlink].Reset();
                    await this.progTaskList[jlink].Run();
                }
            }
            else
            {
                MsgWindow msgWindow = new MsgWindow();
                ProgViewModel.ProgProcess.ProgStep step = (cell.Item as ProgViewModel.ProgProcess).Steps[cell.Column.DisplayIndex];
                msgWindow.SetResult(step.Text);
                msgWindow.SetMsg(step.DetailMsg);
                msgWindow.SetTitle("J-Link SN: " + (cell.Item as ProgViewModel.ProgProcess).Steps[ProgViewModel.N_JLinkSN].Text);
                msgWindow.SetStep(this.view.ProgView.StepTitles[cell.Column.DisplayIndex]);
                msgWindow.Show();
            }
        }
Example #31
0
        public static DataGridCell GetCell(DataGridCellInfo dataGridCellInfo)
        {
            if (!dataGridCellInfo.IsValid)
            {
                return null;
            }

            var cellContent = dataGridCellInfo.Column.GetCellContent(dataGridCellInfo.Item);
            if (cellContent != null)
            {
                return (DataGridCell)cellContent.Parent;
            }
            else
            {
                return null;
            }
        }
        // Private helper returning the automation peer coresponding to cellInfo
        // Cell can be virtualized
        private DataGridCellItemAutomationPeer GetCellItemPeer(DataGridCellInfo cellInfo)
        {
            if (cellInfo.IsValid)
            {
                DataGridItemAutomationPeer dataGridItemAutomationPeer = GetOrCreateItemPeer(cellInfo.Item);
                if (dataGridItemAutomationPeer != null)
                {
                    return dataGridItemAutomationPeer.GetOrCreateCellItemPeer(cellInfo.Column);
                }
            }

            return null;
        }
Example #33
0
        /// <summary>
        ///     There was general input on a row header that indicated that
        ///     selection should occur on the given row.
        /// </summary>
        /// <param name="row">The target row.</param>
        /// <param name="startDragging">Whether the input also indicated that dragging should start.</param>
        internal void HandleSelectionForRowHeaderAndDetailsInput(DataGridRow row, bool startDragging)
        {
            object rowItem = row.Item;

            // When not dragging, move focus to the first cell
            if (!_isDraggingSelection && (_columns.Count > 0))
            {
                if (!IsKeyboardFocusWithin)
                {
                    // In order for CurrentCell to move focus, the
                    // DataGrid needs to be focused.
                    Focus();
                }

                DataGridCellInfo currentCell = CurrentCell;
                if (currentCell.Item != rowItem)
                {
                    // Change the CurrentCell if the row is different
                    CurrentCell = new DataGridCellInfo(rowItem, ColumnFromDisplayIndex(0), this);
                }
                else
                {
                    if (_currentCellContainer != null && _currentCellContainer.IsEditing)
                    {
                        // End the pending edit even for the same row
                        EndEdit(CommitEditCommand, _currentCellContainer, DataGridEditingUnit.Cell, /* exitEditingMode = */ true);
                    }
                }
            }

            // Select a row when the mode is not None and the unit allows selecting rows
            if (CanSelectRows)
            {
                MakeFullRowSelection(rowItem, /* allowsExtendSelect = */ true, /* allowsMinimalSelect = */ true);

                if (startDragging)
                {
                    BeginRowDragging();
                }
            }
        }
Example #34
0
        /// <summary>
        ///     Updates the IsSelected property on cells due to a change in SelectedCells.
        /// </summary>
        private void UpdateIsSelected(VirtualizedCellInfoCollection cells, bool isSelected)
        {
            if (cells != null)
            {
                int numCells = cells.Count;
                if (numCells > 0)
                {
                    // Determine if it would be better to iterate through all the visible cells
                    // instead of through the update list.
                    bool useTracker = false;
                    
                    // For "small" updates it's simpler to just go through the cells, get the container,
                    // and update IsSelected. For "large" updates, it's faster to go through the visible
                    // cells, see if they're in the collection, and then update IsSelected.
                    // Determining small vs. large is going to be done using a magic number.
                    // 750 is close to the number of visible cells Excel shows by default on a 1280x1024 monitor.
                    if (numCells > 750)
                    {
                        int numTracker = 0;
                        int numColumns = _columns.Count;

                        ContainerTracking<DataGridRow> rowTracker = _rowTrackingRoot;
                        while (rowTracker != null)
                        {
                            numTracker += numColumns;
                            if (numTracker >= numCells)
                            {
                                // There are more cells visible than being updated
                                break;
                            }
                     
                            rowTracker = rowTracker.Next;
                        }

                        useTracker = (numCells > numTracker);
                    }

                    if (useTracker)
                    {
                        ContainerTracking<DataGridRow> rowTracker = _rowTrackingRoot;
                        while (rowTracker != null)
                        {
                            DataGridRow row = rowTracker.Container;
                            DataGridCellsPresenter cellsPresenter = row.CellsPresenter;
                            if (cellsPresenter != null)
                            {
                                ContainerTracking<DataGridCell> cellTracker = cellsPresenter.CellTrackingRoot;
                                while (cellTracker != null)
                                {
                                    DataGridCell cell = cellTracker.Container;
                                    DataGridCellInfo cellInfo = new DataGridCellInfo(cell);
                                    if (cells.Contains(cellInfo))
                                    {
                                        cell.SyncIsSelected(isSelected);
                                    }

                                    cellTracker = cellTracker.Next;
                                }
                            }

                            rowTracker = rowTracker.Next;
                        }
                    }
                    else
                    {
                        foreach (DataGridCellInfo cellInfo in cells)
                        {
                            DataGridCell cell = TryFindCell(cellInfo);
                            if (cell != null)
                            {
                                cell.SyncIsSelected(isSelected);
                            }
                        }
                    }
                }
            }
        }
Example #35
0
 internal void SelectOnlyThisCell(DataGridCellInfo currentCellInfo)
 {
     using (UpdateSelectedCells())
     {
         _selectedCells.Clear();
         _selectedCells.Add(currentCellInfo);
     }
 }
Example #36
0
 /// <summary>
 ///     Notification that a particular cell's IsSelected property changed.
 /// </summary>
 internal void CellIsSelectedChanged(DataGridCell cell, bool isSelected)
 {
     if (!IsUpdatingSelectedCells)
     {
         DataGridCellInfo cellInfo = new DataGridCellInfo(cell);
         if (isSelected)
         {
             _selectedCells.AddValidatedCell(cellInfo);
         }
         else if (_selectedCells.Contains(cellInfo))
         {
             _selectedCells.Remove(cellInfo);
         }
     }
 }
        void ISelectionItemProvider.AddToSelection()
        {
            // If item is already selected - do nothing
            DataGridCellInfo currentCellInfo = new DataGridCellInfo(_item, _column);
            if (this.OwningDataGrid.SelectedCellsInternal.Contains(currentCellInfo))
            {
                return;
            }

            EnsureEnabled();
        
            if (this.OwningDataGrid.SelectionMode == DataGridSelectionMode.Single &&
                this.OwningDataGrid.SelectedCells.Count > 0)
            {
                throw new InvalidOperationException();
            }

            this.OwningDataGrid.SelectedCellsInternal.Add(currentCellInfo);
        }
        void ISelectionItemProvider.Select()
        {
            EnsureEnabled();

            DataGridCellInfo currentCellInfo = new DataGridCellInfo(_item, _column);
            this.OwningDataGrid.SelectOnlyThisCell(currentCellInfo);
        }
Example #39
0
        private void OnEnterKeyDown(KeyEventArgs e)
        {
            DataGridCell currentCellContainer = CurrentCellContainer;
            if ((currentCellContainer != null) && (_columns.Count > 0))
            {
                e.Handled = true;

                DataGridColumn column = currentCellContainer.Column;

                // Commit any current edit
                if (CommitAnyEdit() && ((e.KeyboardDevice.Modifiers & ModifierKeys.Control) == 0))
                {
                    bool shiftModifier = ((e.KeyboardDevice.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift);

                    // Go to the next row, keeping the column the same
                    int numItems = Items.Count;
                    int index = Math.Max(0, Math.Min(numItems - 1, Items.IndexOf(currentCellContainer.RowDataItem) + (shiftModifier ? -1 : 1)));

                    if (index < numItems)
                    {
                        object rowItem = Items[index];
                        ScrollIntoView(rowItem, column);

                        if (CurrentCell.Item != rowItem)
                        {
                            // Focus the new cell
                            CurrentCell = new DataGridCellInfo(rowItem, column, this);

                            // Will never edit on ENTER, so just say that the old cell wasn't in edit mode
                            SelectAndEditOnFocusMove(e, currentCellContainer, /* wasEditing = */ false, /* allowsExtendSelect = */ false, /* ignoreControlKey = */ true);
                        }
                        else
                        {
                            // When the new item jumped to the bottom, CurrentCell doesn't actually change,
                            // but there is a new container.
                            currentCellContainer = CurrentCellContainer;
                            if (currentCellContainer != null)
                            {
                                currentCellContainer.Focus();
                            }
                        }
                    }
                }
            }
        }
Example #40
0
 private DataGridCell TryFindCell(DataGridCellInfo info)
 {
     // Does not de-virtualize cells
     return TryFindCell(info.Item, info.Column);
 }
        void ISelectionItemProvider.RemoveFromSelection()
        {
            EnsureEnabled();

            DataGridCellInfo currentCellInfo = new DataGridCellInfo(_item, _column);
            if (this.OwningDataGrid.SelectedCellsInternal.Contains(currentCellInfo))
            {
                this.OwningDataGrid.SelectedCellsInternal.Remove(currentCellInfo);
            }
        }
Example #42
0
        /// <summary>
        ///     Processes selection for a row.
        ///     Depending on the current keyboard state, this may mean
        ///     - Selecting the row
        ///     - Deselecting the row
        ///     - Deselecting other rows
        ///     - Extending selection to the row
        /// </summary>
        /// <remarks>
        ///     ADO.Net has a bug (#524977) where if the row is in edit mode
        ///     and atleast one of the cells are edited and committed without
        ///     commiting the row itself, DataView.IndexOf for that row returns -1
        ///     and DataView.Contains returns false. The Workaround to this problem 
        ///     is to try to use the previously computed row index if the operations 
        ///     are in the same row scope.
        /// </remarks>
        private void MakeFullRowSelection(object dataItem, bool allowsExtendSelect, bool allowsMinimalSelect)
        {
            bool extendSelection = allowsExtendSelect && ShouldExtendSelection;
            
            // minimalModify means that previous selections should not be cleared
            // or that the particular item should be toggled.
            bool minimalModify = allowsMinimalSelect && ShouldMinimallyModifySelection;

            using (UpdateSelectedCells())
            {
                bool alreadyUpdating = IsUpdatingSelectedItems;
                if (!alreadyUpdating)
                {
                    BeginUpdateSelectedItems();
                }

                try
                {
                    if (extendSelection)
                    {
                        // Extend selection from the anchor to the item
                        int numColumns = _columns.Count;
                        if (numColumns > 0)
                        {
                            ItemCollection items = Items;
                            int startIndex = items.IndexOf(_selectionAnchor.Value.Item);
                            int endIndex = items.IndexOf(dataItem);
                            if (startIndex > endIndex)
                            {
                                // Ensure that startIndex is before endIndex
                                int temp = startIndex;
                                startIndex = endIndex;
                                endIndex = temp;
                            }

                            if ((startIndex >= 0) && (endIndex >= 0))
                            {
                                IList selectedItems = SelectedItems;
                                int numItemsSelected = selectedItems.Count;

                                if (!minimalModify)
                                {
                                    bool clearedCells = false;

                                    // Unselect items not within the selection range
                                    for (int index = 0; index < numItemsSelected; index++)
                                    {
                                        object item = selectedItems[index];
                                        int itemIndex = items.IndexOf(item);

                                        if ((itemIndex < startIndex) || (endIndex < itemIndex))
                                        {
                                            // Selector has been signaled to delay updating the
                                            // collection until we have finished the entire update.
                                            // The item will actually remain in the collection
                                            // until EndUpdateSelectedItems.
                                            selectedItems.RemoveAt(index);

                                            if (!clearedCells)
                                            {
                                                // We only want to clear if something is actually being removed.
                                                _selectedCells.Clear();
                                                clearedCells = true;
                                            }
                                        }
                                    }
                                }
                                else 
                                {
                                    // If we hold Control key - unselect only the previous drag selection (between CurrentCell and endIndex)
                                    int currentCellIndex = items.IndexOf(CurrentCell.Item);
                                    int removeRangeStartIndex = -1;
                                    int removeRangeEndIndex = -1;
                                    if (currentCellIndex < startIndex)
                                    {
                                        removeRangeStartIndex = currentCellIndex;
                                        removeRangeEndIndex = startIndex - 1;
                                    }
                                    else if (currentCellIndex > endIndex)
                                    {
                                        removeRangeStartIndex = endIndex + 1;
                                        removeRangeEndIndex = currentCellIndex;
                                    }

                                    if (removeRangeStartIndex >= 0 && removeRangeEndIndex >= 0)
                                    {
                                        for (int index = 0; index < numItemsSelected; index++)
                                        {
                                            object item = selectedItems[index];
                                            int itemIndex = items.IndexOf(item);

                                            if ((removeRangeStartIndex <= itemIndex) && (itemIndex <= removeRangeEndIndex))
                                            {
                                                // Selector has been signaled to delay updating the
                                                // collection until we have finished the entire update.
                                                // The item will actually remain in the collection
                                                // until EndUpdateSelectedItems.
                                                selectedItems.RemoveAt(index);
                                            }
                                        }

                                        _selectedCells.RemoveRegion(removeRangeStartIndex, 0, removeRangeEndIndex - removeRangeStartIndex + 1, Columns.Count);
                                    }
                                }

                                // Select the children in the selection range
                                IEnumerator enumerator = ((IEnumerable)items).GetEnumerator();
                                for (int index = 0; index <= endIndex; index++)
                                {
                                    if (!enumerator.MoveNext())
                                    {
                                        // In case the enumerator ends unexpectedly
                                        break;
                                    }

                                    if (index >= startIndex)
                                    {
                                        selectedItems.Add(enumerator.Current);
                                    }
                                }

                                _selectedCells.AddRegion(startIndex, 0, endIndex - startIndex + 1, _columns.Count);
                            }
                        }
                    }
                    else
                    {
                        if (minimalModify && SelectedItems.Contains(dataItem))
                        {
                            // Unselect the one item
                            UnselectItem(dataItem);
                        }
                        else
                        {
                            if (!minimalModify || !CanSelectMultipleItems)
                            {
                                // Unselect the other items
                                if (_selectedCells.Count > 0)
                                {
                                    // Pre-emptively clear the SelectedCells collection, which is O(1),
                                    // instead of waiting for the selection change notification to clear
                                    // SelectedCells row by row, which is O(n).
                                    _selectedCells.Clear();
                                }
                     
                                if (SelectedItems.Count > 0)
                                {
                                    SelectedItems.Clear();
                                }
                            }

                            if (_editingRowIndex >= 0 && _editingRowItem == dataItem)
                            {
                                // ADO.Net bug HACK, see remarks.
                                int numColumns = _columns.Count;
                                if (numColumns > 0)
                                {
                                    _selectedCells.AddRegion(_editingRowIndex, 0, 1, numColumns);
                                }

                                SelectItem(dataItem, false);
                            }
                            else
                            {
                                // Select the item
                                SelectItem(dataItem);
                            }
                        }

                        _selectionAnchor = new DataGridCellInfo(dataItem, ColumnFromDisplayIndex(0), this);
                    }
                }
                finally
                {
                    if (!alreadyUpdating)
                    {
                        EndUpdateSelectedItems();
                    }
                }
            }
        }
Example #43
0
        /// <summary>
        ///     There was general input on a row header that indicated that
        ///     selection should occur on the given row.
        /// </summary>
        /// <param name="row">The target row.</param>
        /// <param name="startDragging">Whether the input also indicated that dragging should start.</param>
        internal void HandleSelectionForRowHeaderAndDetailsInput(DataGridRow row, bool startDragging)
        {
            object rowItem = row.Item;

            // When not dragging, move focus to the first cell
            if (!_isDraggingSelection && (_columns.Count > 0))
            {
                if (!IsKeyboardFocusWithin)
                {
                    // In order for CurrentCell to move focus, the
                    // DataGrid needs to be focused.
                    Focus();
                }

                CurrentCell = new DataGridCellInfo(rowItem, ColumnFromDisplayIndex(0), this);
            }

            // Select a row when the mode is not None and the unit allows selecting rows
            if (CanSelectRows)
            {
                MakeFullRowSelection(rowItem, /* allowsExtendSelect = */ true, /* allowsMinimalSelect = */ true);

                if (startDragging)
                {
                    BeginRowDragging();
                }
            }
        }
Example #44
0
        /// <summary>
        ///     Process selection on a cell.
        ///     Depending on the current keyboard state, this may mean
        ///     - Selecting the cell
        ///     - Deselecting the cell
        ///     - Deselecting other cells
        ///     - Extending selection to the cell
        /// </summary>
        /// <remarks>
        ///     ADO.Net has a bug (#524977) where if the row is in edit mode
        ///     and atleast one of the cells are edited and committed without
        ///     commiting the row itself, DataView.IndexOf for that row returns -1
        ///     and DataView.Contains returns false. The Workaround to this problem 
        ///     is to try to use the previously computed row index if the operations 
        ///     are in the same row scope.
        /// </remarks>
        private void MakeCellSelection(DataGridCellInfo cellInfo, bool allowsExtendSelect, bool allowsMinimalSelect)
        {
            bool extendSelection = allowsExtendSelect && ShouldExtendSelection;

            // minimalModify means that previous selections should not be cleared
            // or that the particular item should be toggled.
            bool minimalModify = allowsMinimalSelect && ShouldMinimallyModifySelection;

            using (UpdateSelectedCells())
            {
                int cellInfoColumnIndex = cellInfo.Column.DisplayIndex;
                if (extendSelection)
                {
                    // Extend selection from the anchor to the cell
                    ItemCollection items = Items;

                    int startIndex = items.IndexOf(_selectionAnchor.Value.Item);
                    int endIndex = items.IndexOf(cellInfo.Item);

                    if (_editingRowIndex >= 0)
                    {
                        // ADO.Net bug HACK, see remarks.
                        if (_selectionAnchor.Value.Item == _editingRowItem)
                        {
                            startIndex = _editingRowIndex;
                        }

                        if (cellInfo.Item == _editingRowItem)
                        {
                            endIndex = _editingRowIndex;
                        }
                    }

                    DataGridColumn anchorColumn = _selectionAnchor.Value.Column;
                    int startColumnIndex = anchorColumn.DisplayIndex;
                    int endColumnIndex = cellInfoColumnIndex;

                    if ((startIndex >= 0) && (endIndex >= 0) &&
                        (startColumnIndex >= 0) && (endColumnIndex >= 0))
                    {
                        int newRowCount = Math.Abs(endIndex - startIndex) + 1;
                        int newColumnCount = Math.Abs(endColumnIndex - startColumnIndex) + 1;

                        if (!minimalModify)
                        {
                            // When extending cell selection, clear out any selected items
                            if (SelectedItems.Count > 0)
                            {
                                UnselectAll();
                            }

                            _selectedCells.Clear();
                        }
                        else
                        {
                            // Remove the previously selected region
                            int currentCellIndex = items.IndexOf(CurrentCell.Item);
                            if (_editingRowIndex >= 0 &&
                                _editingRowItem == CurrentCell.Item)
                            {
                                // ADO.Net bug HACK, see remarks.
                                currentCellIndex = _editingRowIndex;
                            }

                            int currentCellColumnIndex = CurrentCell.Column.DisplayIndex;

                            int previousStartIndex = Math.Min(startIndex, currentCellIndex);
                            int previousRowCount = Math.Abs(currentCellIndex - startIndex) + 1;
                            int previousStartColumnIndex = Math.Min(startColumnIndex, currentCellColumnIndex);
                            int previousColumnCount = Math.Abs(currentCellColumnIndex - startColumnIndex) + 1;

                            _selectedCells.RemoveRegion(previousStartIndex, previousStartColumnIndex, previousRowCount, previousColumnCount);

                            if (SelectionUnit == DataGridSelectionUnit.CellOrRowHeader)
                            {
                                int removeRowStartIndex = previousStartIndex;
                                int removeRowEndIndex = previousStartIndex + previousRowCount - 1;

                                if (previousColumnCount <= newColumnCount)
                                {
                                    // When no columns were removed, we can check fewer rows
                                    if (previousRowCount > newRowCount)
                                    {
                                        // One or more rows were removed, so only check those rows
                                        int removeCount = previousRowCount - newRowCount;
                                        removeRowStartIndex = (previousStartIndex == currentCellIndex) ? currentCellIndex : currentCellIndex - removeCount + 1;
                                        removeRowEndIndex = removeRowStartIndex + removeCount - 1;
                                    }
                                    else
                                    {
                                        // No rows were removed, so don't check anything
                                        removeRowEndIndex = removeRowStartIndex - 1;
                                    }
                                }

                                // For cells that were removed, check if their row is selected
                                for (int i = removeRowStartIndex; i <= removeRowEndIndex; i++)
                                {
                                    object item = Items[i];
                                    if (SelectedItems.Contains(item))
                                    {
                                        // When a cell in a row is unselected, unselect the row too
                                        SelectedItems.Remove(item);
                                    }
                                }
                            }
                        }

                        // Select the cells in rows within the selection range
                        _selectedCells.AddRegion(Math.Min(startIndex, endIndex), Math.Min(startColumnIndex, endColumnIndex), newRowCount, newColumnCount);
                    }
                }
                else
                {
                    bool selectedCellsContainsCellInfo = _selectedCells.Contains(cellInfo);
                    bool singleRowOperation = (_editingRowIndex >= 0 && _editingRowItem == cellInfo.Item);
                    if (!selectedCellsContainsCellInfo &&
                        singleRowOperation)
                    {
                        // ADO.Net bug HACK, see remarks.
                        selectedCellsContainsCellInfo = _selectedCells.Contains(_editingRowIndex, cellInfoColumnIndex);
                    }

                    if (minimalModify && selectedCellsContainsCellInfo)
                    {
                        // Unselect the one cell
                        if (singleRowOperation)
                        {
                            // ADO.Net bug HACK, see remarks.
                            _selectedCells.RemoveRegion(_editingRowIndex, cellInfoColumnIndex, 1, 1);
                        }
                        else
                        {
                            _selectedCells.Remove(cellInfo);
                        }

                        if ((SelectionUnit == DataGridSelectionUnit.CellOrRowHeader) &&
                            SelectedItems.Contains(cellInfo.Item))
                        {
                            // When a cell in a row is unselected, unselect the row too
                            SelectedItems.Remove(cellInfo.Item);
                        }
                    }
                    else
                    {
                        if (!minimalModify || !CanSelectMultipleItems)
                        {
                            // Unselect any items
                            if (SelectedItems.Count > 0)
                            {
                                UnselectAll();
                            }

                            // Unselect all the other cells
                            _selectedCells.Clear();
                        }

                        if (singleRowOperation)
                        {
                            // ADO.Net bug HACK, see remarks.
                            _selectedCells.AddRegion(_editingRowIndex, cellInfoColumnIndex, 1, 1);
                        }
                        else
                        {
                            // Select the cell
                            _selectedCells.AddValidatedCell(cellInfo);
                        }
                    }

                    _selectionAnchor = cellInfo;
                }
            }
        }