且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Datagridview中创建子行c#

更新时间:2022-02-17 07:05:14

DataGridView 中没有这样的概念。这实际上是一个矩形网格,而不是以随机方式划分某些2D空间的组合或矩形。如果您需要更复杂的设计,可以一个接一个地交错排列不同类型的行。您可以将某些单元格保留为空且不可编辑,您可以将另一个网格的整个实例放在单个单元格中。对于网格视图的同一个实例,只有单元格之间的垂直边界应该是通用的。



作为经验法则的一部分,我不建议玩这个和基于此基础设计您的UI设计。在大多数情况下,我宁愿建议一些向下钻取向下设计:当您选择某个单元格或某些行时,您可以可视化与此单元格相关的详细信息或在单独的控件中。您可以在点击中显示此详细信息,以便用户可以使用它,然后手动删除,进一步向下钻取。这显然反映了主 - 细节概念。



或者,如果你想永久地看到某种程度的细节,从根本上重新设计你的数据的表示,如果不是数据结构化。进一步的建议只能通过详细介绍,这可能超出了快速问题&答案论坛。



-SA
There is no such concept in DataGridView. This is really a rectangular grid, not combination or rectangles dividing some 2D space in a random manner. If you need more complicated design, you can have rows of different types interlaced, one after another. You can leave some cells empty and non-editable, you can put a whole instance of another grid in a single cell. Only the vertical boundaries between cells should be common for the same instance of your grid view.

As a mater of rule of thumb, I would not recommend playing with that and base your UI design based on that. In most cases, I would rather suggest some "drill-down" down design: when you select some cell or some row, you can visualize the detail related to this cell or a row in a separate control. Of you can show this detail information on click, so the user could work with it and later manually remove, of drill down further. This would clearly reflect the master-detail concept.

Or, if you want to see some level of detail permanently, redesign the presentation of your data fundamentally, if not the data structured themselves. The further advice can only be given through going into all the detail, which might be beyond the format of this Quick Questions & Answers forum.

—SA