隐藏LookUpEdit中的列(DevExpress)

时间:2014-08-13 16:01:34

标签: vb.net datatable devexpress

我正在尝试隐藏LookUpEdit控件(DevExpress第三方)的所有列,除了DisplayMember(它的功能应该像stander 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

2 个答案:

答案 0 :(得分:4)

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

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))

答案 1 :(得分:1)

隐藏devexpress的lookupedit控件中的特定列是:

lookUpEdit1.Properties.PopulateColumns();
lookUpEdit1.Properties.Columns[**index**].Visible = false;