sql - 是否可以将未绑定(bind)的列插入到绑定(bind)的数据 GridView 中?

标签 sql vb.net datagridview datagridviewcombobox

我有一个 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 the CellFormatting 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. The CellFormatting 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/

相关文章:

c# - 检测客户端与 TCP/IP 断开连接的正确方法

asp.net - Linq 到 SQL : Group By and Sum()

mysql - 无法将值插入数据库

c# - 有没有办法在datagridview中获取新添加的行?

mysql - 为什么我无法导入数据库

sql - 主键和唯一约束之间的主要区别是什么?

sql - 根据 SQL 或 R 中的某些条件复制行

c# - 将 DataGridView 绑定(bind)到 List<>,某些属性不应显示

c# - 将 csv 读取到网格的更快方法

mysql - 如何将 sql 格式更改为天数而不是数字?