Tag: datagridviewtextboxcell

如何将DataGridView单元格的字体设为特定颜色?

此代码适用于使单元格的背景为蓝色: DataGridViewRow dgvr = dataGridViewLifeSchedule.Rows[rowToPopulate]; dgvr.Cells[colName].Style.BackColor = Color.Blue; dgvr.Cells[colName].Style.ForeColor = Color.Yellow; …但ForeColor的效果并不是我所期望/希望的:字体颜色仍然是黑色,而不是黄色。 如何将字体颜色设置为黄色?

如何在编辑DataGridViewTextBoxColumn并按EnterKey后阻止进入下一行?

我正在使用DataGridViews编写程序。 在一个DatagridView有一个DataGridViewTextBoxColumn ,可以由用户编辑。 当用户完成键入数字时,他按下键盘上的ENTER。 现在DataGridView完成所有Events ,在所有Events ,最后一件事就是问题。 一切都完成了,Windows将选择下一个DataGridViewRow ,我无法阻止这一点。 我试过了 if (e.KeyData == Keys.Enter) e.SuppressKeyPress = true; // or e.Handled 在我发现的几乎所有事件中。 遗憾的是,当DataGridViewTextBoxColumn未处于编辑模式时,我只能阻止ENTER键。 在编辑中,我的方法是找到ENTER 添加事件 private void dgr_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { e.Control.KeyPress += new KeyPressEventHandler(dgr_KeyPress_NumericTester); } 这是仅接受数字输入的事件。 private void dgr_KeyPress_NumericTester(object sender, KeyPressEventArgs e) { if (!Char.IsDigit(e.KeyChar) && e.KeyChar != 8) e.Handled = true; } 详细解释: […]