gpt4 book ai didi

vb.net - 隐藏 LookUpEdit 中的列 (DevExpress)

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

我正在尝试隐藏除 DisplayMember 之外的 LookUpEdit 控件(DevExpress 3rd party)的所有列(其功能应该看起来像独立的 ComboBox)

Properties.DataSource 是一个 DataTable,因此当我想要访问每一列以隐藏它时,程序会启动 Null ref 异常。

我做错了什么?

代码:

If TypeOf Me.Properties.DataSource Is DataTable Then
Me.Properties.PopulateColumns()
Dim dt As DataTable = CType(Me.Properties.DataSource, DataTable)

For Each column As DataColumn In dt.Columns
If Me.Properties.Columns(column.ColumnName) IsNot Nothing AndAlso column.ColumnName IsNot Me.DisplayMember Then
Me.Properties.Columns(column.ColumnName).Visible = False
End If
Next

End If

最佳答案

您可以只添加所需的一列,而不是隐藏列:

lookUpEdit1.Properties.Columns.Add(New LookUpColumnInfo(lookUpEdit1.Properties.DisplayMember))

这里是示例:

Dim dataTable As New DataTable()

dataTable.Columns.Add("ID", Type.GetType("System.Int32"))
dataTable.Columns.Add("Name", Type.GetType("System.String"))
dataTable.Columns.Add("Description", Type.GetType("System.String"))

dataTable.Rows.Add(0, "Name0", "Description0")
dataTable.Rows.Add(1, "Name1", "Description1")
dataTable.Rows.Add(2, "Name2", "Description2")

lookUpEdit1.Properties.DataSource = dataTable
lookUpEdit1.Properties.DisplayMember = "Name"
lookUpEdit1.Properties.ValueMember = "ID"

lookUpEdit1.Properties.Columns.Add(New LookUpColumnInfo(lookUpEdit1.Properties.DisplayMember))

关于vb.net - 隐藏 LookUpEdit 中的列 (DevExpress),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25290921/

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