如何获取带有垂直列的DataGridView [英] How to get a DataGridView with vertical Columns

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

问题描述

在我的 Winform C#应用程序中,我有一个 DataGridView DataTable 绑定并且具有很多记录的>。
我想以以下格式(参见图像)显示所选行( DataGridView )的详细信息。什么 Control 或(Trick)实现此目的。

In my Winform C# application I have a DataGridView that bound with DataTable and have many records. I want to display details of the selected row (of DataGridView ) in the following Format (see Image).What Control or (Trick) should I use to achieve this.

换句话说:表的第一列应具有列名,第二列应具有其对应值

In other words: "First Column of the Table should have Columns name and 2nd Column should have its corresponding values"

推荐答案

通常,我不会在 DataGridView 中执行此操作,它实际上旨在显示多个记录,而您只想在以下位置显示一个记录:一个时间。我可以建议两种替代的处理方法:

Typically, I wouldn't do this in a DataGridView, its really intended to display multiple records and you only want to display one record at a time. I can suggest two alternate ways of dealing with this:

如果您知道要提前显示的字段,则典型的方法是布置一组单独的值在设计时显示标签和其他简单控件。这具有以下优点:

The typical approach if you know the fields to be displayed ahead of time would be to lay out a set of individual value displaying labels and other simple controls at design time. This has the following advantages:


  • 事物的位置更加灵活

  • 控件的类型用于每个单独字段的都可以定制。例如,一个布尔值可能会显示一个复选框,而不是文本。

  • 该值前面的标签可以本地化为用户语言。即使不是国际申请,有时显示与列的数据库模式名称不同的标签也很有用。

如果如果不知道要在设计时显示的字段,或者不想打扰它们的布局,请使用 PropertyGrid 控件而不是 DataGridView 。我从未真正尝试过使用DataTable作为数据源,但是在 C#/ winforms:如何最好地绑定属性网格和System.Data.DataRow

If you don't know the fields to be displayed at design time, or don't want to bother laying them out, use a PropertyGrid control instead of a DataGridView. I've never actually tried this with a DataTable as a data source, but it looks like there is a well developed answer for that at C#/winforms: how to best bind a propertygrid and a System.Data.DataRow

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

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