// Спуск строки private void MoveRowDown_Click(object sender, EventArgs e) { // Контроль if ((MainDataGrid.Rows.Count < 2) || (MainDataGrid.SelectedCells[0].RowIndex == MainDataGrid.Rows.Count - 1)) { return; } DataTable table = (DataTable)MainDataGrid.DataSource; // Фиксация индекса int insertedIndex = MainDataGrid.SelectedCells[0].RowIndex + 2; // Добавление и заполнение строки table.Rows.InsertAt(table.NewRow(), insertedIndex); table.Rows[insertedIndex].ItemArray = (object[])table.Rows[insertedIndex - 2].ItemArray.Clone(); // Удаление старой строки table.Rows.RemoveAt(insertedIndex - 2); // Переход на сдвинутую строку MainDataGrid.ClearSelection(); MainDataGrid.Rows[insertedIndex - 1].Cells[0].Selected = true; }
private void Window_Loaded(object sender, RoutedEventArgs e) { MainDataGrid.Focus(); if (!string.IsNullOrEmpty(kPw.Settings.PreviouslyLoadedFile) && File.Exists(kPw.Settings.PreviouslyLoadedFile)) { ShowPasswordPanel(kPw.CurrentOperation = EncryptDecryptOperation.Decrypt, kPwFile.TmpPath = kPw.Settings.PreviouslyLoadedFile); } }
private void producto_radio_CheckedChanged(object sender, EventArgs e) { labelGrid1.Text = "Historico de Productos:"; detailDataGrid.Visible = false; total_label.Visible = false; total_input.Visible = false; detail_label.Visible = false; MainDataGrid.Width = 650; MainDataGrid.DataSource = null; MainDataGrid.Refresh(); }
private void ingreso_radio_CheckedChanged(object sender, EventArgs e) { labelGrid1.Text = "Ingreso a Almacen:"; detailDataGrid.Visible = false; total_label.Visible = true; total_input.Visible = true; detail_label.Visible = false; total_input.Text = "00.00"; MainDataGrid.Width = 480; MainDataGrid.DataSource = null; MainDataGrid.Refresh(); }
private void ExportToExcel(string filePath) { MainDataGrid.SelectAllCells(); MainDataGrid.ClipboardCopyMode = DataGridClipboardCopyMode.IncludeHeader; ApplicationCommands.Copy.Execute(null, MainDataGrid); String resultat = (string)Clipboard.GetData(DataFormats.CommaSeparatedValue); String result = (string)Clipboard.GetData(DataFormats.Text); MainDataGrid.UnselectAllCells(); System.IO.StreamWriter file = new System.IO.StreamWriter(filePath); file.WriteLine(result.Replace(',', ' ')); file.Close(); MessageBox.Show("Exporting DataGrid data to Excel file created", "Fitness App", MessageBoxButton.OK, MessageBoxImage.Information); }
public MainWindow() { try { loggingFile = new FileInfo("logs.txt"); InitializeComponent(); this.DataContext = this; sessions = new ObservableCollection <Session>(); databaseConnection = DatabaseConnect(); //TIMER setting mainTicker = new DispatcherTimer(); mainTicker.Interval = new TimeSpan(0, 0, 0, 0, 42); mainTicker.Tick += TimerClock_Tick; mainTicker.Start(); // //CLOCK setting timerClock = new TimerClock(); // //BINDINGS bindingSessionDataGrid = new Binding(); bindingSessionDataGrid.Source = sessions; MainDataGrid.SetBinding(DataGrid.ItemsSourceProperty, bindingSessionDataGrid); // //Load sessions to Collection using (var communicator = new DatabaseCommunicator(DatabaseConnect())) { try { foreach (Session sessionToAdd in communicator.LoadSessions()) { sessions.Add(sessionToAdd); } } catch (Exception ex) { ExceptionLogger.LogException(loggingFile, true, ex); } } } catch (Exception ex) { ExceptionLogger.LogException(loggingFile, true, ex); return; } }
// Удаление строк private void DeleteRow_Click(object sender, EventArgs e) { // Контроль количества строк if (MainDataGrid.Rows.Count <= 2) { MessageBox.Show(Localization.GetText("NotEnoughRowsError", language), ProgramDescription.AssemblyTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } DataTable table = (DataTable)MainDataGrid.DataSource; List <int> indices = new List <int> (); // Индексирование удаляемого диапазона for (int i = 0; i < MainDataGrid.SelectedCells.Count; i++) { if (!indices.Contains(MainDataGrid.SelectedCells[i].RowIndex)) { indices.Add(MainDataGrid.SelectedCells[i].RowIndex); } } indices.Sort(); // Удаление for (int i = 0; i < indices.Count; i++) { table.Rows.RemoveAt(indices[i] - i); } // Переход на заведомо оставшуюся строку if ((indices.Count != 0) && (MainDataGrid.Rows.Count != 0)) { MainDataGrid.ClearSelection(); if (indices[0] - 1 < 0) { MainDataGrid.Rows[0].Cells[0].Selected = true; } else { MainDataGrid.Rows[indices[0] - 1].Cells[0].Selected = true; } } }
private void Dialog_Loaded(object sender, RoutedEventArgs e) { var remove = AlbumList?.FirstOrDefault(f => string.IsNullOrWhiteSpace(f.Id) || f.Id == "♥♦♣♠"); if (remove != null) { AlbumList.Remove(remove); } MainDataGrid.ItemsSource = AlbumList; MainDataGrid.Focus(); if (MainDataGrid.Items.Count > 0) { MainDataGrid.SelectedIndex = 0; MainDataGrid.FocusOnFirstCell(); } }
private void ScrollToRow(SpecObject specObject) { specObject = specObjectsViewModel.SpecObjects.Single(x => x.Identifier == specObject.Identifier); MainDataGrid.SelectedItem = specObject; MainDataGrid.ScrollIntoView(specObject); }
private void Window_Loaded(object sender, RoutedEventArgs e) { //Binding the table to the dataObject MainDataGrid.ItemsSource = matchDataList; //Disabling selection on the table MainDataGrid.SelectionChanged += (obj, ev) => Dispatcher.BeginInvoke(DispatcherPriority.Render, new Action(() => MainDataGrid.UnselectAll())); }