DataSet / DataGridView将选定列设置为变量.VB

时间:2013-02-15 16:05:32

标签: vb.net datagridview datatable

是否可以将选定的数据网格视图列名称设置为变量。

我的代码示例。

    Dim cmevoids As DataTable = ds.Tables(0)
    Dim test As String
    test = "event_code"

    Dim Query = From payments In cmevoids.AsEnumerable() _
                Where payments.Field(Of String)("event_code") = "MB120117"
                Where payments.Field(Of String)("event_transaction_status") = "PAID"
    Order By payments.Field(Of String)("event_code") _
                Select New With {.event_code = payments.Field(Of String)(test), _
                                        .event_transaction_status = payments.Field(Of String)("event_transaction_status"), _
                                        .event_transaction_detail_amount = payments.Field(Of String)("event_transaction_detail_amount")}
    dgvQuery.DataSource = Query.ToList()

我想从第一个数据网格视图的组合框中选择w / e列,并将其显示在查询的第二个数据网格视图中。

我可以让它搜索并显示由测试变量所示的变量选择的表格。但我不能让它将查询数据网格视图中的列名更改为变量的名称。我只能将它命名为w / e我已经硬编码,在这种情况下是event_code,event_transaction_status和event_transaction_detail_amount。

没有硬编码但可变的任何方法吗?

1 个答案:

答案 0 :(得分:0)

如何像你一样填充gridview,然后在绑定后更改它?

Dim Result as string = "w/e column the user selects from a combo box"
Dim i as integer = 0 'your colum index
GridView1.Columns(i).HeaderText = Result