我遇到了一个问题,我需要显示当前使用的特定校准气体,但出于历史原因,我需要保留过期气体。我们的数据库中有超过100条记录,所以它有很长的列表!
该列表正在从SQL Server 2008填充:
SELECT CalGasID, GasConc, GasContent, GasSerialNo, InUse FROM CalibrationGases
我将数据存储到此类中(在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
ComboBox:
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"主列表。
但是其他人是否有更好的方法或方法可以只用一个列表来完成它?
答案 0 :(得分:1)
怎么样:
Me.ComboxBoxGas1.DataSource = _gasConcList.Where(Function(x) x.InUse = True OrElse x.GasID = selectedGasID).ToList()
其中selectedGasID
是最后一个气体校准值。