- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用了CellEndEdit
事件,编辑单元格值后按Enter键,然后单元格焦点向下移动。
我希望焦点返回到我编辑值的原始单元格。
我用了很多方法,但都失败了。
Private Sub DataGridVie1_CellEndEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridVie1.CellEndEdit
'...
'....editing codes here...to input and validate values...
'...
'...
'...before the End If of the procedure I put this values
DataGridVie1.Rows(e.RowIndex).Cells(e.ColumnIndex).Selected = True
DataGridVie1.CurrentCell = DataGridVie1.Rows(e.RowIndex).Cells(e.ColumnIndex)
'DataGridVie1.BeginEdit(False) '''DID NOT apply this because it cause to edit again.
End If
我不知道编辑后或按 ENTER 键后焦点返回到编辑的原始单元格中时的真实代码。
因为每次我按下回车键,它都会直接转到下一个单元格。
将焦点重新定位回编辑的原始单元格的代码是什么。
我知道 EditingControlShowing
方法,但我认为我不必使用该方法来获得我想要的东西。
最佳答案
试试这个:定义 3 个变量。一个用于记住是否进行了编辑操作,另外两个用于存储最后编辑的单元格的行和列索引:
Private flag_cell_edited As Boolean
Private currentRow As Integer
Private currentColumn As Integer
发生编辑操作时,您存储已编辑单元格的坐标,并在 CellEndEdit
事件处理程序中将标志设置为 true:
Private Sub DataGridView1_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
flag_cell_edited = True
currentColumn = e.ColumnIndex
currentRow = e.RowIndex
End Sub
然后在 SelectionChanged
事件处理程序中,使用 currentRow
将 DataGridView
的 CurrentCell
属性设置为最后编辑的单元格和 currentColumn
变量来撤消默认单元格焦点更改:
Private Sub DataGridView1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.SelectionChanged
If flag_cell_edited Then
DataGridView1.CurrentCell = DataGridView1(currentColumn, currentRow)
flag_cell_edited = False
End If
End Sub
关于vb.net - CellEndEdit 之后的 DataGridView SetFocus,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17511317/
我已经看到 Datagridview 不允许复制和粘贴多个单元格的文本,是否有一个简单的设置来启用它,或者我是否必须使用键处理程序和剪贴板数据存储来包含该功能。 用户想要在一行中复制 3 个单元格,并
我有一个 DataGridView我想限制用户只为特定列下的单元格输入数值的控件。我怎样才能在 DataGridView 中完成这种类型的验证细胞? 当我创建一个简单的文本框时是可能的,但是我如何验证
我正在尝试格式化 DataGridView,使用样式颜色等。DGV 在表单启动时加载(通过 buildGrid 方法),如构造函数代码中所示: public Report1(DataSet d
第一列中的小黑三角的官方DataGridView命名法描述是什么? 好像是标记了DataGridView.CurrentRow的位置,但是只是一个get属性,我想设置一下。 Grid with arr
我有点卡在我写的一些代码上 一个大纲是我正在从 SQL 数据库中读取一些数据,并希望将其显示在表单上的 DataGridView 中。我已经确认有数据从数据库返回,但不确定为什么没有出现。我遵循了互联
我的 DataTable从数据库中提取了三列,而我只需要将其中的两列绑定(bind)到 DataGridView .你能帮我吗? 最佳答案 这可能有用 DataSet ds = new DataSet
我有一个包含 Dataset ds 和 DataGridView dgv 的 WinForms 应用程序。 dgv 绑定(bind)到 ds。 ds 通过 Task() 更新,该 Task() 使用
我有DataGridView(dgHome),在parentForm(Home)中有一些列。子 Form(bill) 有 DataGridView(dgbill) 。我需要当我单击 dgHome 中的
我有两个具有相同列架构的 DataGridView(尽管有两个不同的 DataView 作为 DataSource - 如果这很重要)。将一行从一个数据 GridView 移动到另一个数据 GridV
基本上我有 2 个 DataGridView,我需要将行从一个复制到另一个。 到目前为止我已经尝试过: DataGridViewRowCollection tmpRowCollection = Dat
我正在尝试根据它包含的行数使我的 DataGridView 的高度自动调整。目前,我能够通过以下行完成此操作: dataGridView_SearchResults.AutoSize = true;
使用 WinForms、C# .Net 2.0 我正在向非绑定(bind) DataGridView 添加行。我想在其中一列中有一个 DataGridViewButtonColumn,在单击时删除该行
我有一个 datagridview(dataGridView1,其中包含一个 dataGridview2 列标题),其中我有一个复选框列,称为 dgvCkb,在 dataGridView1。当我在任何
对不起,如果这是一个愚蠢的问题。我在这方面很陌生。我应该如何将组合框添加到数据表,然后将其加载到数据 GridView 中?这可以做到吗?这是最好的方法吗?非常感谢有关如何执行此操作的提示和教程。先感
我正在尝试将 .txt 文件导入 DataGrid。问题是虽然代码大部分工作正常,但在导入 .txt 文件时,它会创建额外的行,例如 this ; OpenFileDialog ofd
datagridview 加载速度非常慢。我该如何优化它? datagridview有4-5千行。 我必须根据几个参数动态生成一个 datagridview。(来自数据库的数据,列数) 我必须从数据库
我怎样才能强制DataGridView.CellValueChanged DataGridViewCell.Value 立即引发事件(并将更改实际提交给 ComboBox 属性)单元格中的编辑控件更改
我有一个通过数据集从数据库中获取数据的功能 public DataSet getDataSet(string query) { DataSet ds = new DataSet()
客户希望能够键入一个字母并让系统滚动 DataGridView,这样具有与字母匹配的单元格的第一行将滚动到 DataGridView 的顶部 任何建议将不胜感激 最佳答案 我不确定您将如何有效地查找与
好吧,我有一个 DataGridView,用户可以在其中单击列标题进行排序。当他们在应用排序时添加新行时,直到验证该行时才会创建记录(在退出 newRow 之前他们无法执行此操作)。排序后如何才能选择
我是一名优秀的程序员,十分优秀!