Esempio n. 1
0
        public static void Add_Click(object sender, RoutedEventArgs e)
        {
            DataGridRow row  = ((DependencyObject)sender).FindParent <DataGridRow>();
            DataGrid    grid = row.FindParent <DataGrid>();

            //int rowIndex = row.GetIndex();

            //if (rowIndex < 0 || rowIndex >= grid.Items.Count - 1) return;

            object d = grid.DataContext;

            if (d is BaseViewModel)
            {
                ((BaseViewModel)d).AddRow(row.GetIndex());

                // Force validation on new row
                //DataGridRow newRow = VisualTreeHelper.GetChild(VisualTreeHelper.GetParent(row), row.GetIndex() + 1) as DataGridRow;
                //newRow.BindingGroup.CommitEdit();
            }
            else // OPCMgr
            {
                if (string.Equals(grid.Name, "opcmgrGroupGrid"))
                {
                    ((OPCMgr_ViewModel)d).AddGroup(row.GetIndex());
                }
                else // Items Grid
                {
                    ((OPCMgr_ViewModel)d).AddItem(row.GetIndex());
                }
            }
        }
Esempio n. 2
0
        public static void Remove_Click(object sender, RoutedEventArgs e)
        {
            DataGridRow row  = ((DependencyObject)sender).FindParent <DataGridRow>();
            DataGrid    grid = row.FindParent <DataGrid>();

            if (grid.Items.Count == 1)
            {
                return;
            }

            object d = grid.DataContext;

            if (d is BaseViewModel)
            {
                ((BaseViewModel)d).RemoveRow(row.GetIndex());
            }
            else // OPCMgr
            {
                if (string.Equals(grid.Name, "opcmgrGroupGrid"))
                {
                    ((OPCMgr_ViewModel)d).RemoveGroup(row.GetIndex());
                }
                else // Items Grid
                {
                    ((OPCMgr_ViewModel)d).RemoveItem(row.GetIndex());
                }
            }
        }
Esempio n. 3
0
        private void partyMenu_Drop(object sender, DragEventArgs e)
        {
            var dg = sender as DataGrid;

            if (dg == null)
            {
                return;
            }
            DataGridRow newGridRow = ((DependencyObject)e.OriginalSource).FindVisualParent <DataGridRow>();

            if (newGridRow == null)
            {
                return;
            }
            int newRowIndex = newGridRow.GetIndex();

            var    dgSrc        = e.Data.GetData("DragSource") as DataGrid;
            object origIndexObj = e.Data.GetData("origIndex");

            if (dgSrc == null || origIndexObj == null || (int)origIndexObj == newRowIndex)
            {
                return;
            }
            ViewModel.CurrentTrainer.Party.Pokemon.Move((int)origIndexObj, newGridRow.GetIndex());
        }
Esempio n. 4
0
        public object Convert(object[] value, Type targetType, object parameter, CultureInfo culture)
        {
            DataGridRow row = value[0] as DataGridRow;
            ObservableCollection <Can> Canconfigs = value[1] as ObservableCollection <Can>;

            Canconfigs[row.GetIndex()].Driver = row.GetIndex() + 1;
            return(Canconfigs[row.GetIndex()].Driver.ToString());
        }
        /// <summary>
        /// Find the row and column index of a clicked cell in a datagrid
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DataGrid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            DependencyObject dep = (DependencyObject)e.OriginalSource;

            while (dep != null && !(dep is DataGridCell))
            {
                dep = VisualTreeHelper.GetParent(dep);
                Console.WriteLine(dep);
            }

            if (dep == null)
            {
                return;
            }

            if (dep is DataGridCell)
            {
                DataGridCell cell = dep as DataGridCell;

                // navigate further up the tree to get the row
                while ((dep != null) && !(dep is DataGridRow))
                {
                    dep = VisualTreeHelper.GetParent(dep);
                }

                DataGridRow row = dep as DataGridRow;

                //TODO: these are the row/column indices
                //use these to update the collection with a new time range provided through a dialog box
                Console.WriteLine("Row: {0} Column: {1}", row.GetIndex(), cell.Column.DisplayIndex);

                //check if clicked cell was staff
                if (!(cell.Column.DisplayIndex == 0))
                {
                    //after row and column is found load up dialog to input new start and end times
                    DayScheduleDialog dsd  = new DayScheduleDialog();
                    DayScheduleVM     dsvm = new DayScheduleVM();

                    //populate vm with currently selected cell
                    dsvm.EmployeeIndex = row.GetIndex();
                    dsvm.DayIndex      = cell.Column.DisplayIndex;


                    dsd.DataContext = dsvm;
                    if (dsd.ShowDialog() == true)
                    {
                        Console.WriteLine("{0} to {1}", dsvm.StartTime, dsvm.EndTime);

                        //add new schedule to database
                        vm.AddDaySchedule(dsvm);

                        vm.RefreshDataGrid();
                    }
                }
            }
        }
Esempio n. 6
0
        private void miGradeOneSubmission_Click(object sender, RoutedEventArgs e)
        {
            int row_index = CurrentRow.GetIndex();
            int col_index = CurrentCell.Column.DisplayIndex;

            OnGradeSubmission?.Invoke(this, new ScoreboardClickedEvent()
            {
                Problem = source.Columns[col_index].ColumnName,
                User    = source.Rows[row_index][0].ToString()
            });
        }
Esempio n. 7
0
        private void btnUpdateSpell_Click(object sender, RoutedEventArgs e)
        {
            var index = dgSpell.SelectedIndex;

            if (index < 0)
            {
                MessageBox.Show("Please Select a row");
                return;
            }
            try
            {
                DataGridRow currentRowIndex = dgSpell.ItemContainerGenerator.ContainerFromIndex(index) as DataGridRow;
                DataRow     dr = spellDataTable.Rows[currentRowIndex.GetIndex()];

                dr[0] = ConvertToInteger(tbSpellId.Text);
                dr[1] = ConvertToFloat(tbSpellValue.Text);
                dr[2] = tbSpellDescription.Text;

                spellDataTable.AcceptChanges();
                dgSpell.Items.Refresh();
            }
            catch (Exception ex)
            {
                MessageBox.Show("The row you selected is blank");
                LogError(ex);
            }
        }
Esempio n. 8
0
        private void btnUpdateInt64_Click(object sender, RoutedEventArgs e)
        {
            var index = dgInt64.SelectedIndex;

            if (index < 0)
            {
                MessageBox.Show("Please Select a row");
                return;
            }
            try
            {
                DataGridRow currentRowIndex = dgInt64.ItemContainerGenerator.ContainerFromIndex(index) as DataGridRow;
                DataRow     dr = integer64DataTable.Rows[currentRowIndex.GetIndex()];

                string[] description = cbInt64Props.Text.Split(" ");

                decimal test = ConvertToDecimal(tb64Value.Text);

                dr[0] = ConvertToInteger(cbInt64Props.SelectedIndex.ToString());
                dr[1] = ConvertToDecimal(tb64Value.Text);
                dr[2] = description[1];

                integer64DataTable.AcceptChanges();
                dgInt64.Items.Refresh();
            }
            catch (Exception ex)
            {
                MessageBox.Show("The row you selected is blank");
                LogError(ex);
                // MessageBox.Show($"{ex.Message} \n {ex.StackTrace} \n {ex.Source} \n {ex.TargetSite}");
            }
        }
Esempio n. 9
0
        private void btnUpdateIid_Click(object sender, RoutedEventArgs e)
        {
            var index = dgIid.SelectedIndex;

            if (index < 0)
            {
                MessageBox.Show("Please Select a row");
                return;
            }
            try
            {
                DataGridRow currentRowIndex = dgIid.ItemContainerGenerator.ContainerFromIndex(index) as DataGridRow;
                DataRow     dr = iidDataTable.Rows[currentRowIndex.GetIndex()];

                string[] description = cbIidProps.Text.Split(" ");

                dr[0] = ConvertToInteger(cbIidProps.SelectedIndex.ToString());
                dr[1] = ConvertToInteger(tbiidValue.Text);
                dr[2] = description[1];

                iidDataTable.AcceptChanges();
            }
            catch (Exception ex)
            {
                MessageBox.Show("The row you selected is blank");
                LogError(ex);
            }
        }
Esempio n. 10
0
 private void DataGridRow_MouseEnter(object sender, MouseEventArgs e)
 {
     if (UserSettings.Setting.ShowRightStatus)
     {
         try
         {
             DataGridRow     row = e.Source as DataGridRow;
             DisplayPath     dp  = (DisplayPath)dgPath.Items.GetItemAt(row.GetIndex());
             DirectoryInfo   di  = new DirectoryInfo(dp.PathDirectory);
             FileInfo[]      fi  = di.GetFiles();
             DirectoryInfo[] d   = di.GetDirectories();
             string          fn  = fi.Length == 1 ? "File" : "Files";
             string          dn  = d.Length == 1 ? "Subdirectory" : "Subdirectories";
             stbStatusR.Content = $"Contains {fi.Length:N0} {fn} and {d.Length:N0} {dn}";
         }
         catch (UnauthorizedAccessException ex)
         {
             logTemp.Error(ex, "Error enumerating files and subdirectories");
             stbStatusR.Content = "Not Authorized";
         }
         catch (Exception ex)
         {
             logTemp.Error(ex, "Error enumerating files and subdirectories");
             stbStatusR.Content = "Error";
         }
     }
 }
Esempio n. 11
0
        private void btnUpdatePosition_Click(object sender, RoutedEventArgs e)
        {
            var         index           = dgPosition.SelectedIndex;
            DataGridRow currentRowIndex = dgPosition.ItemContainerGenerator.ContainerFromIndex(index) as DataGridRow;
            DataRow     dr = positionsDataTable.Rows[currentRowIndex.GetIndex()];

            string[] description = cbPosition.Text.Split(" ");

            dr[0] = ConvertToInteger(cbPosition.SelectedIndex.ToString());

            dr[1] = ConvertToLong(tbCellID.Text);

            dr[2] = ConvertToFloat(tbOriginX.Text);
            dr[3] = ConvertToFloat(tbOriginY.Text);
            dr[4] = ConvertToFloat(tbOriginZ.Text);

            dr[5] = ConvertToFloat(tbAngleW.Text);
            dr[6] = ConvertToFloat(tbAngleX.Text);
            dr[7] = ConvertToFloat(tbAngleY.Text);
            dr[8] = ConvertToFloat(tbAngleZ.Text);

            dr[9] = description[1];

            positionsDataTable.AcceptChanges();
        }
        private void MyBill_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
        {
            TextBox tbx = e.EditingElement as TextBox;

            DataGridRow    row    = e.Row;
            int            index  = row.GetIndex();
            DataGridColumn column = e.Column;
            int            col    = column.DisplayIndex;
            //draft.Text = "Count: "+ tbx.Text + "\rRow: "+ index + "\rCol: "+col;
            TextBlock x = myBill.Columns[0].GetCellContent(myBill.Items[index]) as TextBlock;

            foodCnt = Int32.Parse(x.Text);
            foreach (Food food in foodList)
            {
                if (food.ID == Int32.Parse(x.Text))
                {
                    foodList.Remove(food);
                    foodList.Add(new Food()
                    {
                        ID       = food.ID,
                        Category = food.Category,
                        Name     = food.Name,
                        Quantity = Int32.Parse(tbx.Text),
                        Price    = food.Price
                    });
                    billSum();
                    break;
                }
            }
        }
Esempio n. 13
0
        public bool SetFocusOnSelectedRow(object selected, string columnHeader)
        {
            // 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);
        }
        //Convert the Item to an Index
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            try
            {
                DataGridRow row = value as DataGridRow;
                if (row == null)
                {
                    throw new InvalidOperationException($"This converter class can only be used with DataGridRow elements. {value}");
                }

                return(row.GetIndex() + 1);

                //CollectionView cv = (CollectionView)dg.Items;
                ////Get the CollectionView from the DataGrid that is using the converter
                //DataGrid dg = (DataGrid)Application.Current.MainWindow.FindName("planosComerciaisDataGrid");
                ////Get the index of the item from the CollectionView
                //int rowindex = cv.IndexOf(value) + 1;

                //return rowindex.ToString();
            }
            catch (Exception e)
            {
                throw new NotImplementedException(e.Message);
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Update Modified Author when cell edit is ending
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dataGridComment_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
        {
            try
            {
                if (!loadedUI)
                {
                    return;
                }
                if (isCellEditable)
                {
                    isCellEditable = false;
                    bool edited = dataGridComment.CommitEdit(DataGridEditingUnit.Row, true);
                    if (edited)
                    {
                        DataGridRow row     = e.Row;
                        Comment     comment = row.Item as Comment;
                        comment.ModifiedAuthor = Environment.UserName;
                        comment.ModifiedDate   = DateTime.Now;

                        ObservableCollection <Comment> comments = (ObservableCollection <Comment>)dataGridComment.ItemsSource;
                        int rowIndex = row.GetIndex();
                        comments[rowIndex].ModifiedAuthor = Environment.UserName;
                        comments[rowIndex].ModifiedDate   = DateTime.Now;

                        bool updated = BCFDBWriter.BCFDBWriter.UpdateComment(comment);
                    }
                    isCellEditable = true;
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
        }
Esempio n. 16
0
 private void DeckCardMouseDown(object sender, MouseButtonEventArgs e)
 {
     try
     {
         //Hack try catch, this stems from concurrency issues I believe.
         activeCard = FindAncestor <DataGridRow>((DependencyObject)e.OriginalSource);
         if (sender == null)
         {
             return;                 //(from above) Somehow we get a null here
         }
         var ansc = FindAncestor <Expander>((FrameworkElement)sender);
         if (ansc == null)
         {
             return;
         }
         dragSection = (ObservableSection)ansc.DataContext;
         if (activeCard != null)
         {
             int cardIndex = activeCard.GetIndex();
             var getCard   = dragSection.Cards.ElementAt(cardIndex);
             CardSelected(sender, new SearchCardImageEventArgs {
                 SetId = getCard.SetId, Image = getCard.ImageUri, CardId = getCard.Id
             });
         }
     }
     catch (Exception ex)
     {
         Log.Warn("DeckCardMouseDown", ex);
     }
 }
Esempio n. 17
0
        private void Filters_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            DataGrid dg = sender as DataGrid;

            if (dg != null)
            {
                DataGridRow dgr = (DataGridRow)(dg.ItemContainerGenerator.ContainerFromIndex(dg.SelectedIndex));
                if (!dgr.IsEditing)
                {
                    switch (e.Key)
                    {
                    //case Key.Delete:
                    //    ((App)Application.Current).Settings.RefreshFilters();
                    //    break;
                    case Key.Insert:
                        int index = dgr.GetIndex();
                        //if((e.Modifiers & Keys.Shift) != 0)
                        if (e.KeyboardDevice.IsKeyDown(Key.LeftShift) || e.KeyboardDevice.IsKeyDown(Key.RightShift))
                        {
                            index--; // insert before
                        }
                        ((App)Application.Current).Settings.AddEmptyFilterDataAfter(index < -1 ? -1 : index);
                        break;
                    }
                }
            }
        }
Esempio n. 18
0
        private void OnAttachToDataGridRow(DataGridRow dgr)
        {
            int index = dgr.GetIndex() + 1;

            if (this.AssociatedObject != null)
            {
                this.AssociatedObject.Text = index.ToString();
            }

            // Hook into the DataGridRow
            BindingOperations.SetBinding(this, TargetProperty, new Binding("Item")
            {
                Source = dgr
            });

            // Hook into the DataGrid owner.
            DataGrid dg = dgr.FindVisualParent <DataGrid>();

            dg.RowEditEnding += DgRowEditEnding;
            var cv = CollectionViewSource.GetDefaultView(dg.ItemsSource);

            if (cv != null)
            {
                cv.CollectionChanged += this.CvCollectionChanged;
            }
        }
Esempio n. 19
0
 private void PickUpDeckCard(object sender, MouseEventArgs e)
 {
     if (MouseButtonState.Pressed.Equals(e.LeftButton) && activeCard != null)
     {
         try
         {
             int        cardIndex = activeCard.GetIndex();
             var        getCard   = dragSection.Cards.ElementAt(cardIndex);
             DataObject dragCard  = new DataObject("Card", getCard.ToMultiCard(getCard.Quantity));
             if (System.Windows.Forms.Control.ModifierKeys == System.Windows.Forms.Keys.Shift || getCard.Quantity <= 1)
             {
                 dragSection.Cards.RemoveCard(getCard);
                 DragDrop.DoDragDrop(activeCard, dragCard, DragDropEffects.All);
             }
             else
             {
                 RemoveResultCard(null, new SearchCardIdEventArgs {
                     CardId = getCard.Id
                 });
                 DragDrop.DoDragDrop(activeCard, dragCard, DragDropEffects.Copy);
             }
         }
         catch (Exception ex)
         {
             Log.Error(ex);
         }
     }
     activeCard = null;
 }
Esempio n. 20
0
        internal static int GetRowIndex(DataGridCell cell)
        {
            DataGridRow r2       = DataGridRow.GetRowContainingElement(cell);
            int         rowindex = r2.GetIndex();

            return(rowindex);
        }
Esempio n. 21
0
        private void btnUpdateCreateItem_Click(object sender, RoutedEventArgs e)
        {
            var index = dgCreateItems.SelectedIndex;

            try
            {
                DataGridRow currentRowIndex = dgCreateItems.ItemContainerGenerator.ContainerFromIndex(index) as DataGridRow;
                DataRow     dr = createListDataTable.Rows[currentRowIndex.GetIndex()];

                dr[0] = ConvertToInteger(tbCreateItemsDestType.Text);
                dr[1] = ConvertToInteger(tbCreateItemsWCID.Text);
                dr[2] = ConvertToInteger(tbCreateItemsStackSize.Text);
                dr[3] = ConvertToInteger(tbCreateItemsPalette.Text);
                dr[4] = ConvertToFloat(tbCreateItemsDropRate.Text);
                dr[5] = false;
                dr[6] = tbCreateItemsDescription.Text;

                createListDataTable.AcceptChanges();
            }
            catch (Exception ex)
            {
                MessageBox.Show("The row you selected is blank");
                LogError(ex);
            }
        }
Esempio n. 22
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);
        }
Esempio n. 23
0
        private void chkBioDose_Checked(object sender, RoutedEventArgs e)
        {
            VMMetric    metric = ((FrameworkElement)sender).DataContext as VMMetric;
            CheckBox    chkbox = sender as CheckBox;
            DataGridRow row    = dtaMetrics.ContainerFromElement(chkbox) as DataGridRow;

            if (row == null)
            {
                return;
            }

            int         rowIndex = row.GetIndex();
            VMStructure struc    = dtaMetrics.Items[rowIndex] as VMStructure;

            //Get NTCP Parameters
            if (metric.NTCPParameters.AlphaBeta == 0)
            {
                BioDoseConfiguration bioConfig = Myconfig.GetBioDoseConfiguration();
                if (struc.IsTarget)
                {
                    metric.NTCPParameters.AlphaBeta = bioConfig.TargetAlphaBeta;
                }
                else
                {
                    metric.NTCPParameters.AlphaBeta = bioConfig.OrganAlphaBeta;
                }
            }

            UpdateDoseMetrics(struc, metric);
        }
 private void RefreshRowNumber(DataGridRow row)
 {
     if (row != null)
     {
         row.Header = ((row.GetIndex()) + 1).ToString();
     }
 }
        /// <summary>
        /// Metodo che si attiva quando viene effettuato un click sulla cella contenente la checkbox (scelto2)
        /// - Cambia il valore della CheckBox cliccata
        /// - (se la casella cliccata è relativa ad un progetto che non esiste non abilita nessuna funzione)
        /// - se la CheckBox opposta (scelto1) è true la mette a false
        /// - cancella e ricarica la DataGrid
        /// </summary>
        void OnClick2(object sender, RoutedEventArgs e)
        {
            bool        value = ((DataGridCell)sender).Content.ToString().Split(':').Last().Equals("True") ? true : false;
            DataGridRow r2    = DataGridRow.GetRowContainingElement((DataGridCell)sender);
            int         index = r2.GetIndex();

            if (!value)
            {
                if (list[index].prog2 != null)
                {
                    list[index].scelto1 = false;
                    list[index].scelto2 = true;
                }
            }
            else
            {
                list[index].scelto2 = false;
            }
            DataGrid dataGrid = this.FindName("dataGrid2") as DataGrid;

            dataGrid.Items.Clear();
            foreach (Confronto c in list)
            {
                dataGrid.Items.Add(c);
            }
        }
Esempio n. 26
0
        // Button Events
        private void ButtonUpdateSpellPercent_Click(object sender, RoutedEventArgs e)
        {
            var index = dgSpellProbability.SelectedIndex;

            if (index < 0)
            {
                MessageBox.Show("Please Select a row");
                return;
            }
            try
            {
                DataGridRow currentRowIndex = dgSpellProbability.ItemContainerGenerator.ContainerFromIndex(index) as DataGridRow;
                DataRow     dr = SpellBookPercent.Rows[currentRowIndex.GetIndex()];

                dr[0] = MainWindow.ConvertToInteger(tbSpellId.Text);
                dr[1] = MainWindow.ConvertToFloat(tbSpellPercentValue.Text);
                dr[2] = tbSpellDescription.Text;

                SpellBookPercent.AcceptChanges();
                dgSpellProbability.Items.Refresh();
            }
            catch (Exception ex)
            {
                MessageBox.Show("The row you selected is blank");
                MainWindow.LogError(ex);
            }
            CalculateTotalPercentChance(SpellBookPercent, false);
        }
Esempio n. 27
0
        private void DG_Show_Add(object sender, MouseButtonEventArgs e)
        {
            if (DG.SelectedIndex == -1)
            {
                return;
            }
            var elem = (DG.Items[DG.SelectedIndex] as ThisShow);

            if (elem.NegotiationAssistandID > 0)
            {
                MyTools.DeleteRowsByID(G.NegotiationAssistant, false, elem.NegotiationAssistandID);
                elem.NegotiationAssistandID = 0;
            }
            else
            {
                elem.NegotiationAssistandID = MyTools.AddRowFromTable(true, G.NegotiationAssistant,
                                                                      new KeyValuePair <int, object>(C.NegotiationAssistant.Objecte, elem.ID),
                                                                      new KeyValuePair <int, object>(C.NegotiationAssistant.YM, DateControl_Class.SelectMonth));
            }
            DataGridRow row = (DataGridRow)DG.ItemContainerGenerator.ContainerFromIndex(DG.SelectedIndex);

            row.Background   = (DG.Items[row.GetIndex()] as ThisShow).NegotiationAssistandID > 0 ? Brushes.Green : Brushes.White;
            DG.SelectedIndex = DG.SelectedIndex + (DG.SelectedIndex != DG.Items.Count - 1 ? 1 : -1);
            text.Text        = $"План: {Values.Where(x => (x as ThisShow).NegotiationAssistandID > 0).Count()}";
        }
        private void btnDeleteTerm_Click(object sender, RoutedEventArgs e)
        {
            DataGridRow dgr       = null;
            var         visParent = VisualTreeHelper.GetParent(e.OriginalSource as FrameworkElement);

            while (dgr == null && visParent != null)
            {
                dgr       = visParent as DataGridRow;
                visParent = VisualTreeHelper.GetParent(visParent);
            }
            if (dgr == null)
            {
                return;
            }

            var rowIdx = dgr.GetIndex();

            termDatagrid.Items.RemoveAt(rowIdx);


            itemDatagrid.Items.Clear();
            tbHallSearch.Text        = "";
            txtCalendar.Text         = "Odaberite datum";
            tpTimeFrom.SelectedTime  = null;
            tpTimeUntil.SelectedTime = null;
            notes.Text = "";
            ChangeTerm = false;
            return;
        }
Esempio n. 29
0
 private void DeckDrop(object sender, DragEventArgs e)
 {
     if (e.Data.GetDataPresent("Card"))
     {
         _unsaved = true;
         var dragCard = e.Data.GetData("Card") as IMultiCard;
         ObservableSection dropSection = (ObservableSection)((FrameworkElement)sender).DataContext;
         var element = dropSection.Cards.FirstOrDefault(c => c.Id == dragCard.Id);
         if (e.Effects == DragDropEffects.Copy)
         {
             dragCard.Quantity = 1;
         }
         if (element != null)
         {
             element.Quantity = (byte)(element.Quantity + dragCard.Quantity);
         }
         else
         {
             dropSection.Cards.AddCard(dragCard);
             DataGridRow row = FindAncestor <DataGridRow>(e.OriginalSource as FrameworkElement);
             if (row != null && FindAncestor <DataGrid>(row).Items.SortDescriptions.Count == 0) // do not move if no valid target or deck is sorted when dropped
             {
                 dropSection.Cards.Move(dragCard, row.GetIndex());
             }
         }
         removeAdorner();
     }
     e.Handled = true;
 }
Esempio n. 30
0
        /// <summary>
        /// Show context menu.
        /// </summary>
        /// <param name="sender">Object that raised the event.</param>
        /// <param name="e">Event arguments.</param>
        private void dataGridResults_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                _rightClickedCell             = VisualHelper.GetAncestor <DataGridCell>(e.OriginalSource as DependencyObject);
                _menuItemCopyValue.Visibility = (_rightClickedCell != null && _rightClickedCell.Content is TextBlock) ?
                                                System.Windows.Visibility.Visible :
                                                System.Windows.Visibility.Collapsed;

                DataGridRow item = VisualHelper.GetAncestor <DataGridRow>(e.OriginalSource as DependencyObject);
                if (item != null)
                {
                    dataGridResults.SelectedIndex = item.GetIndex();
                    if (dataGridResults.SelectedIndex < dataGridResults.Items.Count - 1)
                    {
                        _contextMenu.PlacementTarget = item;
                        _contextMenu.Placement       = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
                        _contextMenu.IsOpen          = true;
                    }
                }
            }
            catch (Exception err)
            {
                App.HandleException(err);
            }
        }