DataGridView - BindingSource - 单元格/行样式 [英] DataGridView - BindingSource - Cell/Row Style

查看:65
本文介绍了DataGridView - BindingSource - 单元格/行样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio .NET 2005


我有一个DataGridView控件,其中手动创建列以获得更大的灵活性。实质上,DataGridView.DataSource属性设置为BindingSource对象。从那里,BindingSource对象绑定到一个ArrayList - 它允许我用对象更新ArrayList;并且简单地调用BindingSource.ResetBindings()也允许更新DataGridView。


但是我最近发现了DataGridViewRow.DataBoundItem()方法,它允许我识别/检索底层对应于数据行的对象。因此,改变我之前的设计模型可能是不可避免的。


但我仍然无法解决的问题是修改DGV的行(示例DataGridViewRow.DefaultCellStyle)的样式。如何继续使用绑定数据,同时,有界的行的样式特定于其底层对象数据。


更具体地说:



  • 我有一个名为Orders的类,它代表客户下的订单(无论是买卖,价格,时间等)

  • 在实践中 - 大约有20个左右的列必须显示,但在这个例子中,为了简单起见,使用了四个。

  • 取决于订单是买入还是卖出,我希望行到用不同的彩色背景显示。

  • 此应用程序中有多个DGV,每个表的列必须允许轻松添加/更改/删除。因此BindingSource(或类似的东西 - 必须)

  • 真正的问题是订单被放入BindingSource后,我不知道修改DGVRow.DefaultCellStyle的方法。 ..?

  • 或者更好的是,必须有一些方法让我的DGV风格也受限制??

请提供一些帮助,或者非常感谢评论和建议。


解决方案

要添加的另外一条注释:


我已尝试覆盖DataGridView的paint,rowprepaint和rowpostpaint事件,以便在窗体控件绘制屏幕时,样式会自动应用。这适用于少量数据,但一旦数据集达到一个屏幕大小的长度 - 这种方法很快就证明是不合适的。此过程的另一个问题是,每次将新对象添加到绑定源时,DGV将重绘自身,从而导致屏幕出现大的闪烁。


并提示线索?


I am using Visual Studio .NET 2005

I have a DataGridView control in which columns are created manually for greater flexibility. Essentially the DataGridView.DataSource property is set to the BindingSource object. From there, the BindingSource object is bound to an ArrayList - which allows me to update the ArrayList with objects; and simply calling BindingSource.ResetBindings() allows the DataGridView to be updated as well.

However I have recently found about the DataGridViewRow.DataBoundItem() method which allows me to identify/retrieve the underlying object corresponding to the data-row. Therefore change to my previous design model is likely inevitable.

But the problem I still can't seem to solve is modifying the style of the row (example DataGridViewRow.DefaultCellStyle) of the DGV. How do you continue using bound data, and at the same time, rows being bounded are styled specific to their underlying object-data.

More specifically:

  • I have a class called Orders which represent orders placed by the clients (whether to buy or sell, at what price, and when)
  • in practice - there are around 20 or so columns which must be shown, but in this example, four is used for simplicity sake.
  • depending on whether the order is buy or sell, I want the row to be displayed with different colored background.
  • there is more than one DGV in this application and columns of each table must be allowed to be added/changed/removed easily. Hence BindingSource (or something similar - is a must)
  • the real problem is once an Order is placed into the BindingSource, I don't know of a way to modify the DGVRow.DefaultCellStyle...?
  • or better yet, there must be some way for my DGV Style to be bounded as well...?

Please offer some help on this, or comments and suggestions would be greatly appreciated.

 

解决方案

one more comment to add:

I have tried overriding DataGridView's paint, rowprepaint, and rowpostpaint event so that as the window forms control draws the screen, the style is automatically applied. This works for small amounts of data, but once the dataset reaches over the length of one screen size - this method quickly proves inadequate. Also another problem with this process is that each time a new object is added to the binding-source, the DGV will redraw itself causing major flickering of the screen.

and clue?


这篇关于DataGridView - BindingSource - 单元格/行样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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