mysql - 将组合框添加到链接到数据表的数据网格

标签 mysql vb.net datagrid datatable wpfdatagrid

我的程序是一个用 VB.net 编写的 WPF 应用程序。我也接受面向 C# 的答案,因为我应该能够理解和/或转换。

我有一个数据表,我通过 MySqlDataAdapter 从我的 MySQL 数据库中填充数据。

我的 dataGrid 当前有 AutoGenerateColumns="TRUE"。

我通过 DataGrid1.ItemsSource = MyDataTable.DefaultView 将我的 dataTable 数据加载到我的 dataGrid 中

在我的表中,我有一个标记为“callType”的列,我希望它是一个组合框 (DataGridComboBoxColumn)

我已经尝试了各种可以被描述为在黑暗中丢失的镜头。

是否有人能够在正确的方向上插入我或向我展示一些代码,说明如何在与该 dataGrid 的数据链接的 dataGrid 中创建一个组合框列?

最佳答案

检查 How to: Customize Auto-Generated Columns in the DataGrid Control? .它说:

You can handle the AutoGeneratingColumn event to modify, replace, or cancel a column that is being generated. The AutoGeneratingColumn event occurs one time for each public, non-static property in the bound data type when the ItemsSource property is changed and the AutoGenerateColumns property is true.

Xaml:

<DataGrid AutoGeneratingColumn="DataGrid_AutoGeneratingColumn"  />

代码:

Private Sub DataGrid_AutoGeneratingColumn(sender As System.Object, e As System.Windows.Controls.DataGridAutoGeneratingColumnEventArgs)

        If e.PropertyName = "callType" Then

            Dim combo As New DataGridComboBoxColumn

            combo.ItemsSource = MyItemsSource
            combo.DisplayMemberPath = "TypeName" 
            combo.SelectedValuePath = "TypeID"

            Dim comboBinding As New Binding("callType")
            combo.SelectedValueBinding = comboBinding

            e.Column = combo

        End If

    End Sub

关于mysql - 将组合框添加到链接到数据表的数据网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14789778/

相关文章:

.net - 网格或 ListView 行和列重新排序 WPF

mysql - 在 MySQL 中,将每一行中的值设置为同一行上的 DATEDIFF 计算

java - Eclipse SQLite 使用Where 子句进行多个查询

MySQL-优化查询

c# - WIA 常量和值的 Intellisense/文档

c# - 从sql数据源获取数据到asp.net控件

.net - VB.NET 2K8 : How to make all imports visible within a class?

mysql - 将 BLOB 从一台服务器复制到另一台服务器

wpf - 向 WPF DataGrid 添加不在集合中的额外列

c# - Wpf DataGrid 添加新行