Reputation: 926
I got a problem where I need to show specific calibration gases that are in current use, but I need to keep the expired gases for historical reasons. There are over 100 records in our database, so it's a long list!
The list is being populated from a SQL Server 2008:
SELECT CalGasID, GasConc, GasContent, GasSerialNo, InUse FROM CalibrationGases
And I store the data into this class (in 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
And the 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
So what I want is when the InUse is set to TRUE, I want it to be shown in the dropdown list, but I need also to show the the text of the last gas calibration, if it is already there, to be displayed even if it expired (InUse set to FALSE).
My alternative is only make a master list of what gases are currently active, and then when it comes to that record, add the old calibration gas as the first item, and then append the "InUse" master list.
But does someone else have a better way or method where I can do it with just one list?
Upvotes: 0
Views: 74
Reputation: 2617
How about:
Me.ComboxBoxGas1.DataSource = _gasConcList.Where(Function(x) x.InUse = True OrElse x.GasID = selectedGasID).ToList()
where selectedGasID
is the last gas calibration value.
Upvotes: 1