Datagridview vs tablelayoutpanel用于表格输入 [英] Datagridview vs tablelayoutpanel for tabular input

查看:331
本文介绍了Datagridview vs tablelayoutpanel用于表格输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须有一个表格控件,其中包含跨列托管不同控件的单元格。每列将托管相同的控件。例如,第1列中的所有单元格都将包含控件类型标签。



在这些控件中,很少有预定义控件的扩展,例如标签和文本框,而很少是用户定义的控制。



作为第一选择,我选择DGV作为托管控制。

我浏览了所有MSDN文档并从谷歌那里获得了帮助了解DGV可用的东西。我自定义DGVControl和列来托管这些控件。

这是一项冗长的工作,起初也很混乱。用我的要求建立DGV花了将近一个月的时间。不知何故,我实现了80%的所需功能,其余20%对我来说似乎很难,因为有数百行代码可以使托管控制与业务模型协作并满足基本的DGV控件的属性。

然后我决定不使用DGV,因为它将来可能无法扩展。



作为第二选择,我决定使用一个TLP(TableLayoutPanel)。

我在课堂上扩展了基本的TLP并添加了所需的方法。

TLP中的托管控件比DGV更容易。只需3天就可以根据需要进行构建。

不知何故,TLP花费了大量时间来绘制自己。因为,没有内置函数来删除TLP中的特定行,所以我手动删除了所需行中的控件,并将其下面的所有行移到了一行。只有20个条目,TLP需要将近1.5秒来重新绘制自己。

对于代码,没有循环工作太长时间,也没有任何沉重的后台线程可能导致这种情况。 />
我猜TLP不是为了我需要的功能。它只是一个面板,用于在适当的用户体验窗格上进行布局控制。



我被困在这个目的上使用什么。请指导。



我尝试了什么:



花了很多钱时间让DGV和TLP按需要工作但没有帮助。

I got to have a tabular control that will contain cells hosting different controls across columns. Each column will host same control. For e.g., all cells in column 1 will contain control type Label.

Among those controls, few are extension of predefined controls such as label and textbox while few are user defined controls.

As a first choice I opted DGV as hosting control.
I went through all MSDN documents and took help from google as well to learn things available with DGV. I made custom DGVControl and respectively the columns to host those controls.
This was a lengthy work and messy too at first. It took nearly a month to build DGV with my requirements. Somehow I achieved 80% of required functionality and rest 20% seems to be difficult for me since there are hundreds of lines of code for making hosted control cooperate with the business model and also satisfying basic DGV control's properties.
Then I decided to not to use DGV since it might not be scalable in future.

As a 2nd choice, I decided to use a TLP(TableLayoutPanel).
I extended basic TLP in my class and added methods required.
Hosting controls in TLP is much easier than that of DGV. It took just 3 days to build it as required.
Somehow, TLP takes considerable time to Paint itself. Since, there is no built in function to remove a specific row in TLP, I deleted controls from required row manually and shifted all rows below it to one row up. With just 20 entries, TLP takes nearly 1.5 seconds to repaint itself.
For code, there are no loops that are working for too long, neither there are any heavy background thread that can cause this.
I guess TLP is not made for the functionality I need. Its just a panel to layout controls on form for proper UX.

I am stucked what to use for this very purpose. Please guide.

What I have tried:

Spent lots of time making DGV and TLP work as required but no help.

推荐答案

我做了类似于表格布局面板的事情,但我没有删除控件,而是制作了它们无形。设置行以将其高度调整为内容,但由于行中没有可见内容,因此高度将自身调整为零。通过这种方式重新绘制控件的次数要少得多。这意味着您需要将TLP行号的索引保留为逻辑行号,但这并不难维护。



不太确定这种方法是否适用适用于您的情况,但这个概念可能有所帮助。
I did something similar with a Table Layout Panel, but instead of removing the controls, I just made them invisible. The rows were set to adjust their height to contents, but as there were no visible contents in the row, the height adjusted itself to zero. A lot less redrawing of controls required this way. It means you need to keep an index of TLP row numbers to logical row numbers, but that is not too difficult to maintain.

Not too sure if this methodology would be suitable in your case, but the concept may help.


这篇关于Datagridview vs tablelayoutpanel用于表格输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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