gpt4 book ai didi

.net - DataGridView 绑定(bind)到DataTable。获取枚举的组合框

转载 作者:行者123 更新时间:2023-12-02 09:01:40 26 4
gpt4 key购买 nike

如果您有一个 DataTable,其中有一列属于某种枚举类型。

然后将 DataGridView 绑定(bind)到此 DataTable (myDgv.DataSource = myDataTable)..

如何使 DataGridView 在此列的每个单元格中显示一个组合框(或者是下拉列表?您唯一能做的就是选择)?组合框应选择当前值,并可选择其他可能的枚举值。

目前,这些单元格显示为普通的旧式可编辑文本单元格,其中包含枚举值的字符串表示形式。

最佳答案

我建议您阅读Forcing the DataGridView to do my bidding - a tale of ComboBox hackery :

At first I was optimistic about the DataGridView samples (overview)(Download The DataGridView samples), but I didn't see anything that did what I wanted to do: take an enum value and represent it in the grid with a combobox. So, here's how I did it.

您还应该查看How to: Bind Objects to Windows Forms DataGridView Controls :

The following code example demonstrates how to bind a collection of objects to a DataGridView control so that each object displays as a separate row. This example also illustrates how to display a property with an enumeration type in a DataGridViewComboBoxColumn so that the combo box drop-down list contains the enumeration values.

关于.net - DataGridView 绑定(bind)到DataTable。获取枚举的组合框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/748243/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com