Example #1
0
        void OnDataGrid1_CurrentCellChanged(object sender, EventArgs e)
        {
            // Edit as soon as you click on a cell
            // if we don't do this the user has to click twice on the cell in order to edit (Very anoying)
            DataGrid grid = (DataGrid)sender;
            bool     rc   = grid.BeginEdit();

            if (!rc)
            {
                try
                {
                    if (!grid.CommitEdit())
                    {
                        if (!grid.CommitEdit(DataGridEditingUnit.Row, true))
                        {
                            System.Diagnostics.Debug.WriteLine("Why is CommitEdit failing?");
                        }
                    }
                    rc = grid.BeginEdit();
                    if (!rc)
                    {
                        System.Diagnostics.Debug.WriteLine("Why is BeginEdit failing?");
                    }
                } catch {
                }
            }
        }
Example #2
0
        /// <summary>
        /// The reason we handle the mouseup event ourselves, is because with the normal
        /// grid, you first have to select a cell, and only then you can enable/disable a
        /// checkbox. We want to enable/disable the checkbox with 1 click.
        /// </summary>
        /// <param name="e"></param>
        private void DataGrid_MouseDown(System.Windows.Forms.MouseEventArgs e)
        {
            System.Windows.Forms.DataGrid.HitTestInfo theHitTestInfo;

            // Find out what part of the data grid is below the mouse pointer.
            theHitTestInfo = DataGridSpecifySopClasses.HitTest(e.X, e.Y);

            switch (theHitTestInfo.Type)
            {
            case System.Windows.Forms.DataGrid.HitTestType.Cell:
                // If this is the "loaded" column...
                if (theHitTestInfo.Column == 0)
                {
                    // Remember the cell we've changed. We don't want to change this cell when we move the mouse.
                    // (see DataGrid_MouseMove).
                    _MouseEventInfoForDataGrid_LoadedStateChangedForRow = theHitTestInfo.Row;

                    // Get the column style for the "loaded" column.
                    DataGridColumnStyle theDataGridColumnStyle;
                    theDataGridColumnStyle = DataGridSpecifySopClasses.TableStyles[0].GridColumnStyles[0];

                    // Change the "loaded" stated in _DefinitionFilesInfoForDataGrid and the data grid itself.
                    DataGridSpecifySopClasses.BeginEdit(theDataGridColumnStyle, theHitTestInfo.Row);
                    DefinitionFile theDefinitionFile = (DefinitionFile)_DefinitionFilesInfoForDataGrid[theHitTestInfo.Row];
                    theDefinitionFile.Loaded = !theDefinitionFile.Loaded;
                    DataGridSpecifySopClasses.EndEdit(theDataGridColumnStyle, theHitTestInfo.Row, false);


                    // Change the "loaded" state in the session object.
                    string theFullFileName = System.IO.Path.Combine(theDefinitionFile.DefinitionRoot, theDefinitionFile.Filename);

                    if (theDefinitionFile.Loaded)
                    {
                        // The definition file was not loaded yet. Load it now.
                        theSession.DefinitionManagement.LoadDefinitionFile(theFullFileName);
                    }
                    else
                    {
                        // The definition file was loaded. Unload it now.
                        theSession.DefinitionManagement.UnLoadDefinitionFile(theFullFileName);
                    }

                    // Remember the new "loaded" state for the case where the mouse is moved over other
                    // "loaded" checkboxes while keeping the left mouse button pressed.
                    _MouseEventInfoForDataGrid_LoadedStatedAfterMouseDown = theDefinitionFile.Loaded;
                }

                if (theHitTestInfo.Column == 1)
                {
                    DefinitionFile theDefinitionFile = (DefinitionFile)_DefinitionFilesInfoForDataGrid[theHitTestInfo.Row];
                    DefinitionName = theDefinitionFile.Filename;
                }
                break;
            }
        }
Example #3
0
        /// <summary>
        /// Grid最后一列加行和往右拐
        /// </summary>
        /// <typeparam name="Tresult"></typeparam>
        /// <param name="dataGrid"></param>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <param name="li"></param>
        public static void Grid_Right <Tresult>(this DataGrid dataGrid, object sender, KeyEventArgs e) where Tresult : class, new()
        {
            var uie = e.OriginalSource as UIElement;

            if (e.Key == Key.Enter)
            {
                e.Handled = true;
                uie.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
                dataGrid.BeginEdit();
                if (dataGrid.CurrentColumn != null)
                {
                    if (dataGrid.CurrentColumn.IsReadOnly == true)
                    {
                        for (int b = dataGrid.CurrentColumn.DisplayIndex; b < dataGrid.Columns.Count; b++)
                        {
                            for (int k = 0; k < dataGrid.Columns.Count; k++)
                            {
                                if (dataGrid.Columns[k].DisplayIndex == b)
                                {
                                    if (dataGrid.Columns[k].IsReadOnly == false && dataGrid.Columns[k].Visibility == Visibility.Visible)
                                    {
                                        dataGrid.CurrentColumn = dataGrid.Columns[k];
                                        dataGrid.SelectedItem  = dataGrid.CurrentItem;
                                        dataGrid.BeginEdit();
                                        return;
                                    }
                                    else if (k == dataGrid.Columns.Count - 1 && (dataGrid.Columns[k].IsReadOnly == true || dataGrid.Columns[k].Visibility == Visibility.Hidden))
                                    {
                                        if (dataGrid.SelectedIndex != dataGrid.Items.Count - 1)
                                        {
                                            dataGrid.SelectedIndex = dataGrid.SelectedIndex + 1;
                                            dataGrid.CurrentColumn = dataGrid.Columns[0];
                                            dataGrid.CurrentItem   = dataGrid.SelectedItem;
                                            b = 0;
                                        }
                                        else
                                        {
                                            //PropertyInfo p = dataGrid.CurrentItem.GetType();
                                            ObservableCollection <Tresult> li = dataGrid.ItemsSource as ObservableCollection <Tresult>;
                                            li.Insert(dataGrid.SelectedIndex + 1, new Tresult());
                                            dataGrid.SelectedIndex = dataGrid.SelectedIndex + 1;
                                            dataGrid.CurrentColumn = dataGrid.Columns[0];
                                            dataGrid.CurrentItem   = dataGrid.SelectedItem;
                                            b = 0;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Example #4
0
        /// <summary>
        /// Cherche la ligne en fonction de la référence article ou du code barre
        /// </summary>
        /// <param name="dg"></param>
        private void CodeBarreKeyDown(DataGrid dg)
        {
            Debug.Print($"Code barre: {CodeBarre}");

            if (CodeBarre == null)
            {
                return;
            }

            IEnumerable <LigneCommande> r;

            // Ref Gamme ?
            r = Commande.Lignes.Where(s => s.AeRef == CodeBarre.ToUpper());

            // Ref Mag ?
            if (!r.Any())
            {
                r = Commande.Lignes.Where(s => s.ArRef == CodeBarre.ToUpper());
            }

            // Ref Fourn ?
            if (!r.Any())
            {
                r = Commande.Lignes.Where(s => s.RefFourn == CodeBarre.ToUpper());
            }

            // EAN?
            if (!r.Any())
            {
                _dataService.GetRefByGencod(CodeBarre,
                                            (dt, error) => {
                    if (error != null)
                    {
                        // TODO
                        return;
                    }
                    if (dt.Rows.Count == 1)
                    {
                        r = Commande.Lignes.Where(s => s.Ref == dt.Rows[0]["Ref"].ToString());
                    }
                });
            }

            if (r.Any())
            {
                LigneCommande ligne = r.First();
                ligne.RowHidden = false;
                dg.Focus();
                dg.SelectedItem = ligne;
                dg.UpdateLayout();
                dg.ScrollIntoView(dg.SelectedItem);
                dg.CurrentCell = new DataGridCellInfo(dg.SelectedItem, dg.Columns.Single(c => c.Header.ToString() == "Quantité"));
                dg.BeginEdit();
                CodeBarre = string.Empty;
                return;
            }

            CodeBarre = string.Empty;
            //MessageBox.Show("Article non trouvé.");
        }
Example #5
0
        private void OnNewExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            int i = DataGrid.Items.Count - 1;

            DataGrid.CurrentCell = new DataGridCellInfo(DataGrid.Items[i], DataGrid.Columns[0]);
            DataGrid.BeginEdit();
        }
Example #6
0
 void dataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (dataCurGrid.SelectedItems.Count == 1)
     {
         dataCurGrid.BeginEdit();
     }
 }
Example #7
0
// <Snippet1>
    private void EditGrid(DataGrid dataGrid1)
    {
        // Get the selected row and column through the CurrentCell.
        int colNum;
        int rowNum;

        colNum = dataGrid1.CurrentCell.ColumnNumber;
        rowNum = dataGrid1.CurrentCell.RowNumber;
        // Get the selected DataGridColumnStyle.
        DataGridColumnStyle dgCol;

        dgCol = dataGrid1.TableStyles[0].GridColumnStyles[colNum];
        // Invoke the BeginEdit method to see if editing can begin.
        if (dataGrid1.BeginEdit(dgCol, rowNum))
        {
            // Edit row value. Get the DataTable and selected row.
            DataTable myTable;
            DataRow   myRow;
            // Assuming the DataGrid is bound to a DataTable.
            myTable = (DataTable)dataGrid1.DataSource;
            myRow   = myTable.Rows[rowNum];
            // Invoke the Row object's BeginEdit method.
            myRow.BeginEdit();
            myRow[colNum] = "New Value";
            // You must accept changes on both DataRow and DataTable.
            myRow.AcceptChanges();
            myTable.AcceptChanges();
            dataGrid1.EndEdit(dgCol, rowNum, false);
        }
        else
        {
            Console.WriteLine("BeginEdit failed");
        }
    }
Example #8
0
        private void OpenButton_Click(object sender, RoutedEventArgs e)
        {
            // we need to begin edit to force addition of new row
            DataGrid.BeginEdit();
#if SILVERLIGHT
            BatchCharacter batchCharacter = (BatchCharacter)DataGrid.SelectedItem;
#else
            BatchCharacter batchCharacter = (BatchCharacter)DataGrid.CurrentItem;
#endif

            OpenFileDialog dialog = new OpenFileDialog();
#if !SILVERLIGHT
            dialog.DefaultExt = ".xml";
#endif
            dialog.Filter      = "Rawr Xml Character Files | *.xml";
            dialog.Multiselect = false;
            if (dialog.ShowDialog().GetValueOrDefault())
            {
#if SILVERLIGHT
                batchCharacter.RelativePath = dialog.File.Name;
                using (StreamReader reader = dialog.File.OpenText())
                {
                    batchCharacter.Character = Character.LoadFromXml(reader.ReadToEnd());
                }
#else
                batchCharacter.RelativePath = RelativePath(dialog.FileName, AppDomain.CurrentDomain.BaseDirectory);
#endif
            }
        }
Example #9
0
        private void SetNextCell(DataGrid grid)
        {
            int row         = grid.Items.IndexOf(grid.CurrentItem);
            int Col         = grid.Columns.IndexOf(grid.CurrentColumn);
            var currentCell = GetCell(grid, row, Col);

            if (Col + 1 == grid.Columns.Count)
            {
                row = row + 1;
                Col = 0;
            }
            else
            {
                Col = Col + 1;
            }
            var cell = GetCell(grid, row, Col);

            if (cell != null)
            {
                currentCell.IsSelected = false;
                cell.IsSelected        = true;
                cell.Focus();
                if (cell.IsReadOnly)
                {
                    SetNextCell(grid);
                }
                else
                {
                    grid.BeginEdit();
                }
            }
        }
Example #10
0
    private void OnAnyMouseLeftButtonDown(MouseButtonEventArgs e)
    {
        bool     isKeyboardFocusWithin = base.IsKeyboardFocusWithin;
        bool     flag          = (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control;
        DataGrid dataGridOwner = ReflectionHelper.GetPropertyValue <DataGrid>(this, "DataGridOwner");

        if (isKeyboardFocusWithin && !flag && !e.Handled && this.IsSelected)
        {
            if (dataGridOwner != null)
            {
                ReflectionHelper.Execute(dataGridOwner, "HandleSelectionForCellInput",
                                         this, false, true, false);

                if (!this.IsEditing && !this.IsReadOnly)
                {
                    dataGridOwner.BeginEdit(e);
                    e.Handled = true;
                    return;
                }
            }
        }
        else if (!isKeyboardFocusWithin || !this.IsSelected || flag)
        {
            if (!isKeyboardFocusWithin)
            {
                base.Focus();
            }
            if (dataGridOwner != null)
            {
                ReflectionHelper.Execute(dataGridOwner, "HandleSelectionForCellInput",
                                         this, Mouse.Captured == null && flag, true, false);
            }
            e.Handled = true;
        }
    }
        void OnDataGrid1_CurrentCellChanged(object sender, EventArgs e)
        {
            // Edit as soon as you click on a cell
            // if we don't do this the user has to click twice on the cell in order to edit (Very anoying)
            DataGrid grid = (DataGrid)sender;

            grid.BeginEdit();
        }
Example #12
0
 private void ProcessCustomDisplayDataGrid_OnSelected(object sender, RoutedEventArgs e)
 {
     if (e.OriginalSource.GetType() == typeof(DataGridCell))
     {
         DataGrid grid = (DataGrid)sender;
         grid.BeginEdit(e);
     }
 }
Example #13
0
 private void DataGrid_GotFocus(object sender, RoutedEventArgs e)
 {
     if (e.OriginalSource.GetType() == typeof(DataGridCell))
     {
         DataGrid grd = (DataGrid)sender;
         grd.BeginEdit(e);
     }
 }
Example #14
0
        /// <summary>
        /// 日付金額リスト選択変更時
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            DataGrid dataGrid = sender as DataGrid;

            if (dataGrid.SelectedIndex != -1)
            {
                dataGrid.BeginEdit();
            }
        }
Example #15
0
 private void DataGrid_GotFocus(object sender, RoutedEventArgs e)
 {
     if (e.OriginalSource.GetType() == typeof(DataGridCell))
     {
         DataGrid dg = (DataGrid)sender;
         e.Handled = true;
         dg.BeginEdit(e);
     }
 }
Example #16
0
 public void gotFocus(object sender, RoutedEventArgs e)
 {
     if (e.OriginalSource.GetType() == typeof(DataGridCell) &&
         sender.GetType() == typeof(DataGrid))
     {
         DataGrid grid = (DataGrid)sender;
         grid.BeginEdit();
     }
 }
Example #17
0
 private void DataGrid_PreviewKeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Enter)
     {
         DataGrid dataGrid = sender as DataGrid;
         dataGrid.CurrentColumn = dataGrid.Columns[0];
         dataGrid.Focus();
         dataGrid.BeginEdit();
     }
 }
Example #18
0
 /// <summary>
 /// DataGrid event. If included in DataGrid with ComboBox allows the control enters "editMode".
 /// The user needs to click 2 times to open the combo. Without this event the user needs to click 3 times
 /// Example:<DataGrid DataGridCell.Selected="CustomEvent_DataGridCell_Selected"
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public void OnDataGridCell_Selected(object sender, RoutedEventArgs e)
 {
     // Lookup for the source to be DataGridCell
     if (e.OriginalSource.GetType() == typeof(DataGridCell))
     {
         // Starts the Edit on the row;
         DataGrid grd = (DataGrid)sender;
         grd.BeginEdit(e);
     }
 }
Example #19
0
            static void EmulateChangeDate(DataGrid grid, DateTime date)
            {
                EventHandler <DataGridCellEditEndingEventArgs> hanlder = (s, e) =>
                                                                         e.EditingElement.VisualTree().ByType <DatePicker>().Single().SelectedDate = date;

                grid.CellEditEnding += hanlder;
                grid.BeginEdit();
                grid.CommitEdit(DataGridEditingUnit.Row, true);
                grid.CellEditEnding -= hanlder;
            }
 private void DataGrid_GotFocus(object sender, RoutedEventArgs e)
 {
     // Lookup for the source to be DataGridCell
     if (e.OriginalSource.GetType() == typeof(DataGridCell))
     {
         // Starts the Edit on the row;
         DataGrid grd = (DataGrid)sender;
         grd.BeginEdit(e);
     }
 }
Example #21
0
        private void DataGrid_GotFocus(object sender, RoutedEventArgs e)
        {
            DataGrid grd = (DataGrid)sender;

            if (grd == null)
            {
                return;
            }
            grd.BeginEdit(e);
        }
Example #22
0
        private void service_GetTableDataByContextIdCompleted(object sender, GetTableDataByContextIdCompletedEventArgs e)
        {
            this.Busy.IsBusy = false;

            if (e.Error != null)
            {
                e.Error.ShowError();
                return;
            }

            if (e.Result != null)
            {
                var tableData = e.Result.Where(t => t.Tables.Count > 0).OrderBy(t => t.Tables.First().DatabaseName).ToList();

                foreach (var table in tableData)
                {
                    var data = table.Tables.First();
                    if (data.Data.Count == 0)
                    {
                        continue;
                    }
                    var enties = (data.Data as IEnumerable <Dictionary <string, string> >).ToDataSource();
                    if (enties != null)
                    {
                        var tab = new TabItem
                        {
                            Header = data.DatabasePrefix,
                            Tag    = data.DatabaseName,
                        };
                        if (data.Data.Count > 0)
                        {
                            var panel = new StackPanel
                            {
                                Orientation = Orientation.Vertical,
                            };

                            var grid = new DataGrid()
                            {
                                AutoGenerateColumns = true,
                                ItemsSource         = enties,
                                SelectionMode       = DataGridSelectionMode.Single,
                                Tag            = table,
                                IsReadOnly     = false,
                                MaxColumnWidth = 600,
                                MaxHeight      = 600,
                            };
                            grid.BeginEdit();
                            panel.Children.Add(grid);
                            tab.Content = panel;
                        }
                        ListGridTab.Items.Add(tab);
                    }
                }
            }
        }
Example #23
0
        public static void SelectLastRow(DataGrid dataGrid)
        {
            if (dataGrid.Items.Count == 0)
            {
                return;
            }

            SelectRowByIndex(dataGrid, dataGrid.Items.Count - 1);
            dataGrid.Focus();
            dataGrid.BeginEdit();
        }
        private void Item_GotFocus(object sender, RoutedEventArgs e)
        {
            DataGrid grd = (DataGrid)sender;
            if (grd != null)
            {
                grd.BeginEdit(e);

            }
            var currentRowIndex = dg1.Items.IndexOf(dg1.CurrentItem);

        }
Example #25
0
        /// <summary>
        /// 单元格选择改变
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CurrentCellSelectChanged(object sender, EventArgs e)
        {
            if (ContainColumn(DataGrid.CurrentColumn) && DataGrid.SelectedItem != null)
            {
                DataGrid.BeginEdit();

                SetCurrentProvider(DataGrid.CurrentColumn, DataGrid.SelectedItem);

                SetCellControlFocus(DataGrid.CurrentColumn.GetCellContent(DataGrid.SelectedItem));
            }
        }
Example #26
0
        private static void KeyUpHandler(KeyEventArgs e, DataGrid dataGrid)
        {
            //copy
            if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
            {
                if (e.Key == Key.C)
                {
                    var items = dataGrid.SelectedItems;
                    if (items.Count == 0)
                    {
                        return;
                    }

                    //don't let it bubble up so nothing else happens
                    e.Handled = true;

                    //JS supports clipboard, silverlight doesn't, use it
                    var clipboardData = (ScriptObject)HtmlPage.Window.GetProperty("clipboardData");
                    clipboardData.Invoke("setData", "text", ExcelBehavior.GetCellData(items, dataGrid));
                    // MessageBox.Show("Your data is now available for pasting");
                }
                else if (e.Key == Key.V)
                {
                    var    items       = dataGrid.SelectedItems;
                    object startObject = (items.Count > 0 ? items[0] : null);

                    //don't let it bubble up so nothing else happens
                    e.Handled = true;

                    //JS supports clipboard, silverlight doesn't, use it
                    var    clipboardData = (ScriptObject)HtmlPage.Window.GetProperty("clipboardData");
                    string textData      = clipboardData.Invoke("getData", "text").ToString();
                    ExcelBehavior.SetCellData(startObject, dataGrid, textData);
                }
            }
            else
            {
                //don't start editing for nav keys so a left arrow, etc. doesn't put text in a box
                if (dataGrid.Tag == null && !IsNavigationKey(e) && !dataGrid.CurrentColumn.IsReadOnly)
                {
                    bool   isShifty = ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift);
                    string letter   = ((char)e.PlatformKeyCode).ToString();
                    letter = (isShifty ? letter.ToUpper() : letter.ToLower());

                    dataGrid.Tag = letter;

                    //beginedit will fire the focus event
                    //if we try to access the textbox here its text will not be set
                    dataGrid.BeginEdit();
                }
            }
        }
Example #27
0
// <Snippet1>
    private void EditValue()
    {
        int             rowtoedit         = 1;
        CurrencyManager myCurrencyManager =
            (CurrencyManager)this.BindingContext[ds.Tables["Suppliers"]];

        myCurrencyManager.Position = rowtoedit;
        DataGridColumnStyle dgc = dataGrid1.TableStyles[0].GridColumnStyles[0];

        dataGrid1.BeginEdit(dgc, rowtoedit);
        // Insert code to edit the value.
        dataGrid1.EndEdit(dgc, rowtoedit, false);
    }
        private static void GridColumnFastEdit(DataGridCell cell, RoutedEventArgs e)
        {
            if (cell == null || cell.IsEditing || cell.IsReadOnly)
            {
                return;
            }

            DataGrid dataGrid = FindVisualParent <DataGrid>(cell);

            if (dataGrid == null)
            {
                return;
            }

            if (!cell.IsFocused)
            {
                cell.Focus();
            }

            if (cell.Content is CheckBox)
            {
                if (dataGrid.SelectionUnit != DataGridSelectionUnit.FullRow)
                {
                    if (!cell.IsSelected)
                    {
                        cell.IsSelected = true;
                    }
                }
                else
                {
                    DataGridRow row = FindVisualParent <DataGridRow>(cell);
                    if (row != null && !row.IsSelected)
                    {
                        row.IsSelected = true;
                    }
                }
            }
            else
            {
                ComboBox cb = cell.Content as ComboBox;
                if (cb != null)
                {
                    //DataGrid dataGrid = FindVisualParent<DataGrid>(cell);
                    dataGrid.BeginEdit(e);
                    cell.Dispatcher.Invoke(
                        DispatcherPriority.Background,
                        new Action(delegate { }));
                    cb.IsDropDownOpen = true;
                }
            }
        }
Example #29
0
        /// <summary>
        /// Called when a data grid cell got focus.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private static void OnDataGridCellGotFocus(object sender, RoutedEventArgs e)
        {
            if (e.OriginalSource.GetType() == typeof(DataGridCell))
            {
                DataGrid dataGrid = (DataGrid)sender;
                dataGrid.BeginEdit(e);

                Control control = VisualTreeHelpers.FindChild <Control>(e.OriginalSource as DataGridCell);
                if (control != null)
                {
                    control.Focus();
                }
            }
        }
Example #30
0
        private void EditBoxBase_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
        {
            DataGrid dg = this.FindParent <DataGrid>(this);

            if (dg != null)
            {
                try
                {
                    dg.BeginEdit();
                }
                catch
                {
                }
            }
        }