我有一个 datagridview,绑定(bind)到数据和运行膨胀。两列中的数据是整数,但它们具有我希望表单用户看到的含义。
Column 1 Column 2 Column 3 Column 4
_____________________________________________________
Bob 1 2 Yes
Mary 1 3 No
Tod 2 2 No
Beth 3 3 Yes
其中 1、2 和 3 类似于工作技能。所以我想隐藏第 2 列和第 3 列并从 SQL 来回解释。
Column 1 Column 2 Column 3 Column 2a Column 3a Column 4
_______________________________________________________________________________________
Bob 1 2 Accounting Admin Yes
Mary 1 3 Accounting Manager No
Tod 2 2 Architect Admin No
Beth 3 3 IT Manager Yes
只能想象第 2 列和第 3 列是隐藏的,也许 2a 和 3a 是组合框,它们背后有代码将字符串转换为整数。
该项目太大,无法首先修复它以使用字符串。我对其他建议持开放态度,例如制作基于另一个 SQL 命令的数据绑定(bind)和功能的第 2 列和第 3 列组合框。不过,我看不出它是如何工作的。
最佳答案
来自 Data Binding with Windows Forms 2.0: Programming Smart Client Data Applications with .NET :
There are two primary ways to populate the contents of unbound columns: handling the
RowsAdded
event or handling theCellFormatting
event. The former is a good place to set the cell’s value to make it available for programmatic retrieval later. The latter is a good place to provide a value that will be used for display purposes only and won’t be stored as part of the data retained by the grid cells collection. TheCellFormatting
event can also be used to transform values as they are presented in a cell to something different than the value that is actually stored in the data that sits behind the grid.
关于sql - 是否可以将未绑定(bind)的列插入到绑定(bind)的数据 GridView 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24252406/