/// <summary> /// Event handler for checking format in Amount column /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CheckAmount(object sender, DataTableNewRowEventArgs e) { try { if (Convert.ToInt32(e.Row["Amount"]) < 0 || Convert.ToInt32(e.Row["Amount"]) > 100) { MessageBox.Show("Mengde må være et heltall"); //Sets focus on the cell with error EditDataGrid.CurrentCell = new DataGridCellInfo(EditDataGrid.Items[EditDataGrid.Items.Count - 1], EditDataGrid.Columns[0]); EditDataGrid.BeginEdit(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void InitializeUserInterface() { this._grid = new EditDataGrid(); this._grid.BeginInit(); base.SuspendLayout(); Color control = SystemColors.Control; Color window = SystemColors.Window; this._grid.AllowSorting = false; this._grid.BackgroundColor = Color.FromArgb((window.R + (2 * control.R)) / 3, (window.G + (2 * control.G)) / 3, (window.B + (2 * control.B)) / 3); this._grid.BorderStyle = BorderStyle.None; this._grid.CaptionVisible = false; this._grid.DataMember = ""; this._grid.Dock = DockStyle.Fill; this._grid.HeaderForeColor = SystemColors.ControlText; this._grid.Location = new Point(1, 1); this._grid.Name = "_grid"; this._grid.SelectionBackColor = SystemColors.Highlight; this._grid.SelectionForeColor = SystemColors.HighlightText; this._grid.Size = new Size(570, 0x142); this._grid.TabIndex = 0; this._grid.CurrentCellChanged += new EventHandler(this.OnGridCurrentCellChanged); base.Controls.AddRange(new Control[] { this._grid }); base.Name = "TableDataEditor"; base.DockPadding.All = 1; this.BackColor = SystemColors.ControlDark; this._grid.EndInit(); base.ResumeLayout(false); }