DataGridView多列 [英] DataGridView Multiple columns

查看:176
本文介绍了DataGridView多列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




假设我有一个数据库中有一列的表。

如果我试图在DataGridView中显示这个表,它将是显示在一个垂直列中。


我需要在gridview中的3列或4列中显示此列。但不重复,只是数据库中的数据将显示在GV中


任何帮助

Hi,

suppose I have a table with one column in the database.
If I tried to display this table in a DataGridView it will be displayed in one vertical column.

I need to display this column in 3 or 4 columns in the gridview. but without repeating, just the data as it is in the DB table will be displayed in GV

Any help

推荐答案

您是说要将数据库中的单个列拆分为DataGridView中的多个列?


您想如何分解它?每x行,还是表格的高度?如果我甚至没有正确理解你的问题,请告诉我。
Are you saying you want to break that single column in the database up into several columns in a DataGridView?

How do you want to break it up? Every x rows, or by the height of the form? Please let me know if I''m even understanding your problem correctly.


是的,我想将数据库中的单个列分成DataGridView中的几列,我想打破他们通过形式的高度


谢谢
Yeah, I want to break the single column in the database into several columns in the DataGridView, and I want to break them by the Height of the form

Thanks


好的很酷,这就是我的想法,但不想假设。


好​​吧,我想这样做的好方法是以你想要的方式将数据加载到另一个DataTable对象中,然后在你的DGV对象中显示该DataTable。您将需要做一些数学计算,根据DGV高度计算出您想要的行数,如果您希望在调整表单大小时动态重新调整,则需要更新。另外,请记住,我相信你可以调整DataGridView对象中行的行高。


由于DGV将显示不同的DataTable,你可能会想要设置事件以将更改反映回原始DataTable。您还需要确保知道如何将新行/列表示映射回单列数据,以确保更新正确的字段。


这看起来合理吗?可能有更好的方法来做到这一点......但我不认为有任何自动的方法。使用DataGridView的方式。我会告诉你一般的想法让你尝试实施,如果你有任何问题,请告诉我。
Ok cool, that''s what I thought but didn''t want to assume.

Well, I''d imagine a good way to do this would be to load your data into another DataTable object in the way you want, then display that DataTable in your DGV object. You''ll have to do some math to figure out the number of rows you''ll want based on the DGV height, as well as update that if you want it to dynamically readjust itself if you resize the form. Also, remember that I believe you can resize the row height of a row in the DataGridView object.

Since the DGV is going to be displaying a different DataTable, you''ll probably want to have events set up to reflect changes back into your original DataTable. You''ll also need to make sure you''re aware of how you map the new row/column representation back to the single column data in order to make sure you update the correct fields.

Does that seem reasonable? There might be a better way to do this... but I don''t think there''s any "automatic" way with DataGridView. I''ll leave you with the general idea for you to try implementing, and if you have any questions, let me know.


这篇关于DataGridView多列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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