如果单元格在屏幕右侧,则不会触发Datagridview cellformatting [英] Datagridview cellformatting does not fire if cell is off screen to the right

查看:73
本文介绍了如果单元格在屏幕右侧,则不会触发Datagridview cellformatting的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽管cellformatting事件已经过优化,只能在屏幕上显示可见行 - 但对于屏幕外的单元格来说似乎也是一样。



在可见单元格/列的右侧有12-16列,其中有几个屏幕外,我通过列/单元格设置行样式的backgroundcolor属性 - 单元格格式化不会触发...它会触发并触发一旦单元格可见,我就会向右滚动一次更改数据行...





要更好地解释这个:

我有一个带有发票信息的数据网格视图,当行中的日期在未完成的几天内,我想用红色突出显示。现在 - 代码在我的宽屏幕上运行正常,因为所有列都显示。行会变成红色,因为它们应该等等。

然而,在分辨率较低的显示器上,即使窗体最大化,我的触发器单元也会向右消失,而单元格格式化则不会拾取它,因此不应该把它划成红色。



我试过在左边有两个隐藏的单元格,但看起来像cellformatting忽略不可见的单元格显而易见的原因(不是要画一些看不见的东西)。唯一的选择,然后变得丑陋,是将日期优秀单元格移动到前2或3,可能是4列而不是目前的位置。



我在谷歌尝试过一些搜索,但我怀疑我可能会使用不正确的搜索词datagridview cellformatting在单元格向右时不能正常工作而且没什么我认为对我有用。



我想另一个解决方案,就是利用我的发票编号并进行即时查询以检查是否发票记录日期在我设置的边界内,但我希望不会在用户滚动时查询到达数据库。



这是一个错误用.net?我使用vb.net VS2015与4.6的框架。

或是否有一个非绘制的cellformatting类型事件也被触发,所以我可以检查任何单元格内容否则性能增益DGV退出不看所有单元格意味着更大的打击(对我来说无论如何),因为每页记录必须查询数据库中的每条记录。



我尝试了什么:



各种谷歌搜索没有成功。

Although the cellformatting event is nicely optimised to only work on visible rows on-screen - it seems to be also the same for cells that are off-screen.

Having 12-16 columns with several of these off-screen to the right of the visible cell/columns, I am setting the backgroundcolor property of a row style via a column/cell - the cellformatting does not fire... It fires and changes the row of the data once I scroll over to the right once the cell is visible...


To explain this better:
I have a datagridview with invoice information that I want to highlight in red when it a date in the row is within a couple of days of being outstanding. Now - the code works fine on my widescreen as all the columns show. Rows turn red as they should etc.
However, on a lower-resolution monitor, even when the form is maximised, my trigger-cell disappears off to the right and cellformatting doesnt pick it up and therefore does not paint the row red as it should.

I have tried having two hidden cells over to the left but it looks like cellformatting ignores invisible cells for obvious reasons (its not going to paint something invisible). The only alternative and then it gets ugly, is to move the date outstanding cell pretty much to within the first 2 or 3, maybe 4 columns instead of where it is at the moment.

I have tried a few searches in Google but I suspect I may be using the incorrect search term "datagridview cellformatting not working when cell is to the right" and it nothing that I can see useful for me.

I guess another solution, is to utilise my "invoice number" and do an on-the-fly query to check if the invoice record date is within the boundariesI have set ,but i was hoping not to do queries that are hitting the database while a user scrolls around either.

Is this a bug with .net ? Im using vb.net VS2015 with 4.6 of the framework.
or is there a non-paint-enabled "cellformatting type" event that also gets triggered so i can examine any cell contents otherwise the performance gain that DGV gets out of not looking at all cells means a much bigger hit (for me anyway) by having to query the database for every record, per page of records.

What I have tried:

Various google searches without success.

推荐答案

如果DataGridView或决定单元格样式的列是只读的,则应在RowsAdded事件中更改行的DefaultCellStyle。添加新行时,此事件仅发生一次。应该评估您正在检查的条件,并在那里设置行的DefaultCellStyle。



如果datagridview是可编辑的,或者条件基于的单元格是可编辑的,那么使用CommitEdit事件来更改DefaultCellStyle
If your DataGridView or the columns that decide cell style are read-only, you should change DefaultCellStyle of rows in RowsAdded event. This event occurs only once when a new row is added. The condition you are examining should be evaluated then and DefaultCellStyle of the row should be set there.

If the datagridview is editable or the cells the condition is based on are editable then use the CommitEdit event to change DefaultCellStyle


这篇关于如果单元格在屏幕右侧,则不会触发Datagridview cellformatting的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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