在 ComboBox 上显示某些项目
Displaying certain items on a ComboBox
我遇到了一个问题,我需要显示当前使用的特定校准气体,但由于历史原因我需要保留过期气体。我们的数据库中有超过 100 条记录,所以这是一个很长的列表!
正在从 SQL Server 2008 填充列表:
SELECT CalGasID, GasConc, GasContent, GasSerialNo, InUse FROM CalibrationGases
然后我将数据存储到此 class(在 VB.Net 2008 年):
Public Class GasInfo
Private _gasID As String
Private _Conc As String
Private _serial As String
Private _inUse As Boolean
Public Property GasID() As String
Get
Return Me._gasID
End Get
Set(ByVal value As String)
Me._gasID = value
End Set
End Property
Public Property Concentration() As String
Get
Return Me._Conc
End Get
Set(ByVal value As String)
Me._Conc = value
End Set
End Property
Public Property Serial() As String
Get
Return Me._serial
End Get
Set(ByVal value As String)
Me._serial = value
End Set
End Property
Public Property InUse() As Boolean
Get
Return Me._inUse
End Get
Set(ByVal value As Boolean)
Me._inUse = value
End Set
End Property
Public Sub New()
Me._gasID = String.Empty
Me._Conc = String.Empty
Me._serial = String.Empty
Me._inUse = False
End Sub
Public Sub New(ByVal gasID, ByVal conc, ByVal id, ByVal inUse)
Me._gasID = gasID
Me._Conc = conc
Me._serial = id
Me._inUse = inUse
End Sub
End Class
组合框:
Private _gasConcList As New List(Of GasInfo)
Me.ComboBoxGas1.DataSource = _gasConcList
Me.ComboBoxGas1.DisplayMember = "Concentration"
Me.ComboBoxGas1.ValueMember = "GasID"
Me.ComboBoxGas1.DropDownStyle = ComboBoxStyle.DropDownList
所以我想要的是当 InUse 设置为 TRUE 时,我希望它显示在下拉列表中,但我还需要显示最后一次气体校准的文本,如果它已经存在的话,即使过期也会显示(InUse 设置为 FALSE)。
我的替代方法是只制作一份当前活跃气体的主列表,然后当涉及到该记录时,将旧校准气体添加为第一项,然后附加 "InUse" 主列表.
但是其他人是否有更好的方式或方法让我只用一个列表就可以做到这一点?
怎么样:
Me.ComboxBoxGas1.DataSource = _gasConcList.Where(Function(x) x.InUse = True OrElse x.GasID = selectedGasID).ToList()
其中 selectedGasID
是最后一次气体校准值。
我遇到了一个问题,我需要显示当前使用的特定校准气体,但由于历史原因我需要保留过期气体。我们的数据库中有超过 100 条记录,所以这是一个很长的列表!
正在从 SQL Server 2008 填充列表:
SELECT CalGasID, GasConc, GasContent, GasSerialNo, InUse FROM CalibrationGases
然后我将数据存储到此 class(在 VB.Net 2008 年):
Public Class GasInfo
Private _gasID As String
Private _Conc As String
Private _serial As String
Private _inUse As Boolean
Public Property GasID() As String
Get
Return Me._gasID
End Get
Set(ByVal value As String)
Me._gasID = value
End Set
End Property
Public Property Concentration() As String
Get
Return Me._Conc
End Get
Set(ByVal value As String)
Me._Conc = value
End Set
End Property
Public Property Serial() As String
Get
Return Me._serial
End Get
Set(ByVal value As String)
Me._serial = value
End Set
End Property
Public Property InUse() As Boolean
Get
Return Me._inUse
End Get
Set(ByVal value As Boolean)
Me._inUse = value
End Set
End Property
Public Sub New()
Me._gasID = String.Empty
Me._Conc = String.Empty
Me._serial = String.Empty
Me._inUse = False
End Sub
Public Sub New(ByVal gasID, ByVal conc, ByVal id, ByVal inUse)
Me._gasID = gasID
Me._Conc = conc
Me._serial = id
Me._inUse = inUse
End Sub
End Class
组合框:
Private _gasConcList As New List(Of GasInfo)
Me.ComboBoxGas1.DataSource = _gasConcList
Me.ComboBoxGas1.DisplayMember = "Concentration"
Me.ComboBoxGas1.ValueMember = "GasID"
Me.ComboBoxGas1.DropDownStyle = ComboBoxStyle.DropDownList
所以我想要的是当 InUse 设置为 TRUE 时,我希望它显示在下拉列表中,但我还需要显示最后一次气体校准的文本,如果它已经存在的话,即使过期也会显示(InUse 设置为 FALSE)。
我的替代方法是只制作一份当前活跃气体的主列表,然后当涉及到该记录时,将旧校准气体添加为第一项,然后附加 "InUse" 主列表.
但是其他人是否有更好的方式或方法让我只用一个列表就可以做到这一点?
怎么样:
Me.ComboxBoxGas1.DataSource = _gasConcList.Where(Function(x) x.InUse = True OrElse x.GasID = selectedGasID).ToList()
其中 selectedGasID
是最后一次气体校准值。