cellmouseleave并输入datagridview c#winform 2010 [英] cellmouseleave and enter in datagridview c# winform 2010

查看:130
本文介绍了cellmouseleave并输入datagridview c#winform 2010的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


使用以下数据填充datagridview:

Hi,
The datagridview is populated with data using :

...
dgvMain.DataSource = dataTable;
...


我在dgvMain_CellMouseEnter和dgvMain_CellMouseLeave事件中有代码,这些事件为您指向的单元格上色.
当edatagridview的列和行数较少时,这可以很好地工作.
但是似乎datagridview很大,即具有更多的行和列,那么当我将鼠标移到单元格上方时,我看到闪烁的感觉就像是网格在重新绘制自身一样?
您知道如何避免在单元格上移动时闪烁吗?
谢谢

这是我正在使用的那种代码,并且确实进行着色.


I have code in dgvMain_CellMouseEnter and dgvMain_CellMouseLeave events which colours the cell you are pointing to.
This works fine when th edatagridview has small number of columns and rows.
But it seems if the datagridview is large i.e. with more columns and rows then as I move the mouse over the cells, I see flashes as if the grid is re-painting itself?
Do you know how to avoid this flashing as you are moving over cells?
Thanks

This is the kind of code I am using and does the colouring corectly.

if (dgvMain[e.ColumnIndex, e.RowIndex].Style.BackColor == Color.SkyBlue)
                   {

                   }
                   else
                   {
                       dgvMain[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.Gold;
                  }

推荐答案

我可以想到的一件事是,尽管跟踪网格本身的代码也可以做到这一点,但它还是要跟踪最后一个事件处理的单元格.像这样的东西:

if(e.ColumnIndex!= PreviousColumnIndex || e.RowIndex!= PreviousRowIndex){
//做一些着色
}

另外,启用双重缓冲以防止屏幕闪烁:
http://stackoverflow.com/Questions/118528/horrible-redraw-performance-of-the-datagridview-on-of-my-two-screens [
One thing I can think of, although I would expect the code of the grid itself would also do this, is to keep track of the last cell that was handled by the event. Something like:

if(e.ColumnIndex != PreviousColumnIndex || e.RowIndex != PreviousRowIndex) {
// Do some coloring
}

Also, enable double buffering to prevent screen flickering:
http://stackoverflow.com/questions/118528/horrible-redraw-performance-of-the-datagridview-on-one-of-my-two-screens[^]

Good luck!



它提到了以下内容,但不确定我应该在什么地方放置此代码以及其他什么内容,即需要引用.
你能帮忙吗?
谢谢
Hi,
It mentions the following but not sure where in the form I should place this code and what else i.e. references are required.
Can you assis please?
Thanks
Here is some code that sets the property using reflection, without subclassing as Benoit suggests.
typeof(DataGridView).InvokeMember( 
   "DoubleBuffered",  
   BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty, 
   null,  
   myDataGridViewObject,  
   new object[] { true }); 


这篇关于cellmouseleave并输入datagridview c#winform 2010的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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