DataGridView中的Tab键会引发错误 [英] Tabbing in DataGridView throws Error

查看:91
本文介绍了DataGridView中的Tab键会引发错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!



我试图在datagridview中实现tab到一行中下一个单元格的能力。我目前有一个组合框(不是datagridview的一部分)覆盖文本框单元格。我们需要的是基于这样一个事实,即我们正在寻找的是datagridview组合框单元格无法实现的。



这是我到目前为止完成标签的方法一个单元格到另一个单元格:



  private   void  dataGridView1_CellEnter( object  sender,DataGridViewCellEventArgs e)
{
if ((dataGridView1.CurrentCell.ColumnIndex > 0 )&&(dataGridView1 .CurrentCell.ColumnIndex < = 7 ))
{
dataGridView1.ClearSelection ();
dataGridView1.Rows [e.RowIndex] .Cells [e.ColumnIndex] .Selected = true ;
vehicleGridComboBox.Location = this .dataGridView1.GetCellDisplayRectangle(e.ColumnIndex,e.RowIndex, true )位置;
}
else if (dataGridView1.CurrentCell.ColumnIndex > 7
{
vehicleGridComboBox.Hide();
}
}





我遇到的问题是我收到此错误文本:

System.InvalidOperationException未处理

消息=操作无效,因为它导致对SetCurrentCellAddressCore函数的可重入调用。



有谁知道这意味着什么?错误指向datagridview1.clearselection()下面的行。



谢谢大家!

解决方案

< blockquote>我要感谢Payrok。我删除了有问题的行,它在组合框现在跟随所选标签的位置工作,而不是保持放置。


Hi everyone!

I am trying to implement in a datagridview the ability to tab to the next cell within a row. I currently have a combobox (not part of the datagridview) laying over the text box cells. We needed that based on the fact that what we were looking for was not possible with the datagridview combobox cells.

Here is what I have so far to accomplish the tabbing from one cell to another:

private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
{
     if ((dataGridView1.CurrentCell.ColumnIndex > 0) && (dataGridView1.CurrentCell.ColumnIndex <= 7))
     {
          dataGridView1.ClearSelection();
          dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Selected = true;
          vehicleGridComboBox.Location = this.dataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true).Location;
     }
     else if (dataGridView1.CurrentCell.ColumnIndex > 7)
     {
          vehicleGridComboBox.Hide();
     }
}



The issue I'm running into is is that I'm getting this error with the text:
System.InvalidOperationException was unhandled
Message=Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function.

Does anyone know what this means? The error is pointing to the line below "datagridview1.clearselection()".

Thanks everyone!

解决方案

My thanks to Payrok. I removed the offending line and it works where the combobox follows the selected tab now instead of staying put.


这篇关于DataGridView中的Tab键会引发错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆